Top Description Fields Constructors Methods
org.apache.derby.tools

public Class JDBCDisplayUtil

extends Object
Class Inheritance
Imports
java.io.PrintStream, .PrintWriter, .File, .FileNotFoundException, .IOException, java.sql.Connection, .SQLException, .SQLWarning, .Statement, .PreparedStatement, .ResultSet, .ResultSetMetaData, .Types, java.util.Properties, .Enumeration, .ArrayList, .List, .Vector, org.apache.derby.iapi.tools.i18n.LocalizedResource, org.apache.derby.impl.tools.ij.ijException

This class contains utility methods for displaying JDBC objects and results.

All of the methods are static. The output stream to write to is always passed in, along with the JDBC objects to display.

Field Summary

Modifier and TypeField and Description
private static final int
private static int
private static final int
private static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
checkNotNull(Object
the object to test
o
,
String
the information to include in the error if it is null
what
)

Check if an object is null, and if it is, throw an exception with an informative parameter about what was null.

public static int
DisplayBanner(PrintWriter
the place to write to
out
,
ResultSetMetaData
the ResultSetMetaData to use
rsmd
)

Print a banner containing the column labels separated with '|'s and a line of '-'s.

public static int
public static void
DisplayCurrentRow(PrintWriter
the place to write to
out
,
ResultSet
the ResultSet in use
rs
,
Connection
the Connection against which the ResultSet was retrieved
conn
)

Display the current row of the result set along with a banner.

public static void
public static void
DisplayMultipleResults(PrintWriter
the place to write to
out
,
List<ResultSet>
list of ResultSets to display
resultSets
,
Connection
the connection against which the ResultSets were retrieved
conn
,
int[]
column numbers to display, null if all
displayColumns
,
int[]
column widths, in characters, if displayColumns is specified
displayColumnWidths
)

private static void
DisplayNestedResults(PrintWriter
the place to write to
out
,
Vector<ResultSet>
the vector of results
nr
,
Connection
the Connection against which the ResultSet was retrieved
conn
,
int
number of tab stops to indent line
indentLevel
)

private static void
DisplayNestedResults(PrintStream out, Vector<ResultSet> nr, Connection conn, int indentLevel)

public static void
DisplayNextRow(PrintWriter
the place to write to
out
,
ResultSet
the ResultSet in use
rs
,
Connection
the Connection against which the ResultSet was retrieved
conn
)

Fetch the next row of the result set, and if it exists format and display a banner and the row.

public static void
public static void
DisplayResults(PrintWriter
the place to write to
out
,
Statement
the Statement to display
stmt
,
Connection
the Connection against which the statement was executed
conn
)

Pretty-print the results of a statement that has been executed.

public static void
DisplayResults(PrintWriter
the place to write to
out
,
ResultSet
the ResultSet to display
rs
,
Connection
the connection against which the ResultSet was retrieved
conn
,
int[]
column numbers to display, null if all
displayColumns
,
int[]
column widths, in characters, if displayColumns is specified
displayColumnWidths
)

public static void
public static void
private static void
DisplayRow(PrintWriter
the place to write to
out
,
ResultSet
the ResultSet to use
rs
,
ResultSetMetaData
the ResultSetMetaData to use
rsmd
,
int rowLen, Vector<ResultSet> nestedResults, Connection conn, int
number of tab stops to indent line
indentLevel
,
int[]
A list of column numbers to display
displayColumns
,
int[]
If displayColumns is set, the width of columns to display, in characters.
displayColumnWidths
)

Print one row of a result set, padding each field to the display width and separating them with '|'s

private static void
DisplayRow(PrintStream out, ResultSet rs, ResultSetMetaData rsmd, int rowLen, Vector<ResultSet> nestedResults, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

pack-priv static void
DisplayUpdateCount(PrintWriter
the place to write to
out
,
int
the update count to display
count
,
int
number of tab stops to indent line
indentLevel
)

pack-priv static void
DisplayUpdateCount(PrintStream out, int count, int indentLevel)

public static void
doTrace(PrintWriter
the output stream to write to
out
,
Exception
the exception to display
e
)

If the property ij.exceptionTrace is true, display the stack trace to the print stream.

public static void
private static int[]
getColumnDisplayWidths(ResultSetMetaData rsmd, int[] dispColumns, boolean localizedOutput)

Calculates column display widths from the default widths of the result set.

public static boolean
private static boolean
getSystemBoolean(final String
name of the property
name
)

Get an ij boolean system property.

private static void
indent(PrintWriter out, int indentLevel)

private static void
indent(PrintStream out, int indentLevel)

private static int
indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static int
indent_DisplayBanner(PrintStream out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayCurrentRow(PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayCurrentRow(PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayNextRow(PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayNextRow(PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayResults(PrintWriter out, Statement stmt, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayResults(PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayResults(PrintWriter out, List<ResultSet> resultSets, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayResults(PrintStream out, Statement stmt, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indent_DisplayResults(PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths)

private static void
indentedPrintLine(PrintWriter out, int indentLevel, String text)

private static void
indentedPrintLine(PrintWriter out, int indentLevel, StringBuffer text)

private static void
indentedPrintLine(PrintStream out, int indentLevel, String text)

private static void
indentedPrintLine(PrintStream out, int indentLevel, StringBuffer text)

public static String

Returns:

if s is non-null, s; else nullValue.
mapNull
(String
the string to test for null
s
,
String
the value to use if s is null
nullValue
)

Map the string to the value if it is null.

public static void
setMaxDisplayWidth(int maxDisplayWidth)

public static void
setShowSelectCount(boolean newValue)

public static void
ShowException(PrintWriter
the place to write to
out
,
Throwable
the exception to display
e
)

Print information about the exception to the given PrintWriter.

public static void
public static void
ShowSQLException(PrintWriter
the place to write to
out
,
SQLException
the exception to display
e
)

Print information about the SQL exception to the given PrintWriter.

public static void
public static void
ShowWarnings(PrintWriter
the place to write to
out
,
Connection
the connection that may have warnings.
theConnection
)

Print information about the SQL warnings for the connection to the given PrintWriter.

public static void
ShowWarnings(PrintWriter
the place to write to
out
,
SQLWarning
the SQLWarning
warning
)

public static void
ShowWarnings(PrintWriter
the place to write to
out
,
ResultSet
the ResultSet that may have warnings on it
rs
)

Print information about the SQL warnings for the ResultSet to the given PrintWriter.

public static void
ShowWarnings(PrintWriter
the place to write to
out
,
Statement
the Statement that may have warnings on it
s
)

Print information about the SQL warnings for the Statement to the given PrintWriter.

public static void
ShowWarnings(PrintStream out, Connection theConnection)

public static void
public static void
public static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_RETRIESback to summary
private static final int MAX_RETRIES
maxWidthback to summary
private static int maxWidth
MINWIDTHback to summary
private static final int MINWIDTH
showSelectCountback to summary
private static boolean showSelectCount

Constructor Detail

JDBCDisplayUtilback to summary
public JDBCDisplayUtil()

Method Detail

checkNotNullback to summary
public static void checkNotNull(Object o, String what)

Check if an object is null, and if it is, throw an exception with an informative parameter about what was null. The exception is a run-time exception that is internal to ij.

Parameters
o:Object

the object to test

what:String

the information to include in the error if it is null

DisplayBannerback to summary
public static int DisplayBanner(PrintWriter out, ResultSetMetaData rsmd) throws SQLException

Print a banner containing the column labels separated with '|'s and a line of '-'s. Each field is as wide as the display width reported by the metadata.

Parameters
out:PrintWriter

the place to write to

rsmd:ResultSetMetaData

the ResultSetMetaData to use

Exceptions
SQLException:
on JDBC access failure
DisplayBannerback to summary
public static int DisplayBanner(PrintStream out, ResultSetMetaData rsmd) throws SQLException
DisplayCurrentRowback to summary
public static void DisplayCurrentRow(PrintWriter out, ResultSet rs, Connection conn) throws SQLException

Display the current row of the result set along with a banner. Assume the result set is on a row.

Parameters
out:PrintWriter

the place to write to

rs:ResultSet

the ResultSet in use

conn:Connection

the Connection against which the ResultSet was retrieved

Exceptions
SQLException:
on JDBC access failure
DisplayCurrentRowback to summary
public static void DisplayCurrentRow(PrintStream out, ResultSet rs, Connection conn) throws SQLException
DisplayMultipleResultsback to summary
public static void DisplayMultipleResults(PrintWriter out, List<ResultSet> resultSets, Connection conn, int[] displayColumns, int[] displayColumnWidths) throws SQLException
Parameters
out:PrintWriter

the place to write to

resultSets:List<ResultSet>

list of ResultSets to display

conn:Connection

the connection against which the ResultSets were retrieved

displayColumns:int[]

column numbers to display, null if all

displayColumnWidths:int[]

column widths, in characters, if displayColumns is specified

Exceptions
SQLException:
on JDBC access failure
DisplayNestedResultsback to summary
private static void DisplayNestedResults(PrintWriter out, Vector<ResultSet> nr, Connection conn, int indentLevel) throws SQLException
Parameters
out:PrintWriter

the place to write to

nr:Vector<ResultSet>

the vector of results

conn:Connection

the Connection against which the ResultSet was retrieved

indentLevel:int

number of tab stops to indent line

Exceptions
SQLException:
thrown on access error
DisplayNestedResultsback to summary
private static void DisplayNestedResults(PrintStream out, Vector<ResultSet> nr, Connection conn, int indentLevel) throws SQLException
DisplayNextRowback to summary
public static void DisplayNextRow(PrintWriter out, ResultSet rs, Connection conn) throws SQLException

Fetch the next row of the result set, and if it exists format and display a banner and the row.

Parameters
out:PrintWriter

the place to write to

rs:ResultSet

the ResultSet in use

conn:Connection

the Connection against which the ResultSet was retrieved

Exceptions
SQLException:
on JDBC access failure
DisplayNextRowback to summary
public static void DisplayNextRow(PrintStream out, ResultSet rs, Connection conn) throws SQLException
DisplayResultsback to summary
public static void DisplayResults(PrintWriter out, Statement stmt, Connection conn) throws SQLException

Pretty-print the results of a statement that has been executed. If it is a select, gathers and prints the results. Display partial results up to the first error. If it is not a SELECT, determine if rows were involved or not, and print the appropriate message.

Parameters
out:PrintWriter

the place to write to

stmt:Statement

the Statement to display

conn:Connection

the Connection against which the statement was executed

Exceptions
SQLException:
on JDBC access failure
DisplayResultsback to summary
public static void DisplayResults(PrintWriter out, ResultSet rs, Connection conn, int[] displayColumns, int[] displayColumnWidths) throws SQLException
Parameters
out:PrintWriter

the place to write to

rs:ResultSet

the ResultSet to display

conn:Connection

the connection against which the ResultSet was retrieved

displayColumns:int[]

column numbers to display, null if all

displayColumnWidths:int[]

column widths, in characters, if displayColumns is specified

Exceptions
SQLException:
on JDBC access failure
DisplayResultsback to summary
public static void DisplayResults(PrintStream out, Statement stmt, Connection conn) throws SQLException
DisplayResultsback to summary
public static void DisplayResults(PrintStream out, ResultSet rs, Connection conn) throws SQLException
DisplayRowback to summary
private static void DisplayRow(PrintWriter out, ResultSet rs, ResultSetMetaData rsmd, int rowLen, Vector<ResultSet> nestedResults, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException

Print one row of a result set, padding each field to the display width and separating them with '|'s

Parameters
out:PrintWriter

the place to write to

rs:ResultSet

the ResultSet to use

rsmd:ResultSetMetaData

the ResultSetMetaData to use

indentLevel:int

number of tab stops to indent line

displayColumns:int[]

A list of column numbers to display

displayColumnWidths:int[]

If displayColumns is set, the width of columns to display, in characters.

Exceptions
SQLException:
thrown on JDBC access failure
DisplayRowback to summary
private static void DisplayRow(PrintStream out, ResultSet rs, ResultSetMetaData rsmd, int rowLen, Vector<ResultSet> nestedResults, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
DisplayUpdateCountback to summary
pack-priv static void DisplayUpdateCount(PrintWriter out, int count, int indentLevel)
Parameters
out:PrintWriter

the place to write to

count:int

the update count to display

indentLevel:int

number of tab stops to indent line

DisplayUpdateCountback to summary
pack-priv static void DisplayUpdateCount(PrintStream out, int count, int indentLevel)
doTraceback to summary
public static void doTrace(PrintWriter out, Exception e)

If the property ij.exceptionTrace is true, display the stack trace to the print stream. Otherwise, do nothing.

Parameters
out:PrintWriter

the output stream to write to

e:Exception

the exception to display

doTraceback to summary
public static void doTrace(PrintStream out, Exception e)
getColumnDisplayWidthsback to summary
private static int[] getColumnDisplayWidths(ResultSetMetaData rsmd, int[] dispColumns, boolean localizedOutput) throws SQLException

Calculates column display widths from the default widths of the result set.

getShowSelectCountback to summary
public static boolean getShowSelectCount()
getSystemBooleanback to summary
private static boolean getSystemBoolean(final String name)

Get an ij boolean system property.

Parameters
name:String

name of the property

indentback to summary
private static void indent(PrintWriter out, int indentLevel)
indentback to summary
private static void indent(PrintStream out, int indentLevel)
indent_DisplayBannerback to summary
private static int indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayBannerback to summary
private static int indent_DisplayBanner(PrintStream out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayCurrentRowback to summary
private static void indent_DisplayCurrentRow(PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayCurrentRowback to summary
private static void indent_DisplayCurrentRow(PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayNextRowback to summary
private static void indent_DisplayNextRow(PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayNextRowback to summary
private static void indent_DisplayNextRow(PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayResultsback to summary
private static void indent_DisplayResults(PrintWriter out, Statement stmt, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayResultsback to summary
private static void indent_DisplayResults(PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayResultsback to summary
private static void indent_DisplayResults(PrintWriter out, List<ResultSet> resultSets, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayResultsback to summary
private static void indent_DisplayResults(PrintStream out, Statement stmt, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indent_DisplayResultsback to summary
private static void indent_DisplayResults(PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException
indentedPrintLineback to summary
private static void indentedPrintLine(PrintWriter out, int indentLevel, String text)
indentedPrintLineback to summary
private static void indentedPrintLine(PrintWriter out, int indentLevel, StringBuffer text)
indentedPrintLineback to summary
private static void indentedPrintLine(PrintStream out, int indentLevel, String text)
indentedPrintLineback to summary
private static void indentedPrintLine(PrintStream out, int indentLevel, StringBuffer text)
mapNullback to summary
public static String mapNull(String s, String nullValue)

Map the string to the value if it is null.

Parameters
s:String

the string to test for null

nullValue:String

the value to use if s is null

Returns:String

if s is non-null, s; else nullValue.

setMaxDisplayWidthback to summary
public static void setMaxDisplayWidth(int maxDisplayWidth)
setShowSelectCountback to summary
public static void setShowSelectCount(boolean newValue)
ShowExceptionback to summary
public static void ShowException(PrintWriter out, Throwable e)

Print information about the exception to the given PrintWriter. For non-SQLExceptions, does a stack trace. For SQLExceptions, print a standard error message and walk the list, if any.

Parameters
out:PrintWriter

the place to write to

e:Throwable

the exception to display

ShowExceptionback to summary
public static void ShowException(PrintStream out, Throwable e)
ShowSQLExceptionback to summary
public static void ShowSQLException(PrintWriter out, SQLException e)

Print information about the SQL exception to the given PrintWriter. Walk the list of exceptions, if any.

Parameters
out:PrintWriter

the place to write to

e:SQLException

the exception to display

ShowSQLExceptionback to summary
public static void ShowSQLException(PrintStream out, SQLException e)
ShowWarningsback to summary
public static void ShowWarnings(PrintWriter out, Connection theConnection)

Print information about the SQL warnings for the connection to the given PrintWriter. Walks the list of exceptions, if any.

Parameters
out:PrintWriter

the place to write to

theConnection:Connection

the connection that may have warnings.

ShowWarningsback to summary
public static void ShowWarnings(PrintWriter out, SQLWarning warning)
Parameters
out:PrintWriter

the place to write to

warning:SQLWarning

the SQLWarning

ShowWarningsback to summary
public static void ShowWarnings(PrintWriter out, ResultSet rs)

Print information about the SQL warnings for the ResultSet to the given PrintWriter. Walk the list of exceptions, if any.

Parameters
out:PrintWriter

the place to write to

rs:ResultSet

the ResultSet that may have warnings on it

ShowWarningsback to summary
public static void ShowWarnings(PrintWriter out, Statement s)

Print information about the SQL warnings for the Statement to the given PrintWriter. Walks the list of exceptions, if any.

Parameters
out:PrintWriter

the place to write to

s:Statement

the Statement that may have warnings on it

ShowWarningsback to summary
public static void ShowWarnings(PrintStream out, Connection theConnection)
ShowWarningsback to summary
public static void ShowWarnings(PrintStream out, SQLWarning warning)
ShowWarningsback to summary
public static void ShowWarnings(PrintStream out, ResultSet rs)
ShowWarningsback to summary
public static void ShowWarnings(PrintStream out, Statement s)