/** * @param out the place to write to * @param warning the SQLWarning */ public static void ShowWarnings(PrintWriter out, SQLWarning warning) { while (warning != null) { String p1 = mapNull(warning.getSQLState(), LocalizedResource.getMessage("UT_NoSqlst_7")); String p2 = mapNull(warning.getMessage(), LocalizedResource.getMessage("UT_NoMessa_8")); out.println(LocalizedResource.getMessage("UT_Warni01", p1, p2)); warning = warning.getNextWarning(); } }
/** * @param out the place to write to * @param count the update count to display * @param indentLevel number of tab stops to indent line */ static void DisplayUpdateCount(PrintWriter out, int count, int indentLevel) { if (count == 1) { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_1RowInserUpdatDelet")); } else if (count >= 0) { indentedPrintLine( out, indentLevel, LocalizedResource.getMessage( "UT_0RowsInserUpdatDelet", LocalizedResource.getNumber(count))); } else { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_StateExecu")); } }
/** * @param out the place to write to * @param nr the vector of results * @param conn the Connection against which the ResultSet was retrieved * @param indentLevel number of tab stops to indent line * @exception SQLException thrown on access error */ private static void DisplayNestedResults( PrintWriter out, Vector nr, Connection conn, int indentLevel) throws SQLException { if (nr == null) return; String b = LocalizedResource.getMessage("UT_JDBCDisplayUtil_16"); String oldString = "0"; for (int i = 0; i < nr.size(); i++) { LocalizedResource.OutputWriter().println(); // just too clever to get the extra +s String t = Integer.toString(i); if (t.length() > oldString.length()) { oldString = t; b = b + LocalizedResource.getMessage("UT_JDBCDisplayUtil_17"); } LocalizedResource.OutputWriter().println(b); LocalizedResource.OutputWriter() .println(LocalizedResource.getMessage("UT_Resul0", LocalizedResource.getNumber(i))); LocalizedResource.OutputWriter().println(b); indent_DisplayResults(out, (ResultSet) nr.elementAt(i), conn, indentLevel, null, null); } }
private static void indent_DisplayNextRow( PrintWriter out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { Vector nestedResults; // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; checkNotNull(rs, "ResultSet"); ResultSetMetaData rsmd = rs.getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); // Only print stuff out if there is a row to be had. if (rs.next()) { int rowLen = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); DisplayRow(out, rs, rsmd, rowLen, nestedResults, conn, indentLevel, null, null); } else { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_NoCurreRow")); } ShowWarnings(out, rs); DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; } // DisplayNextRow
/** * Print information about the SQL exception to the given PrintWriter. Walk the list of * exceptions, if any. * * @param out the place to write to * @param e the exception to display */ public static void ShowSQLException(PrintWriter out, SQLException e) { String errorCode; if (getSystemBoolean("ij.showErrorCode")) { errorCode = LocalizedResource.getMessage("UT_Error0", LocalizedResource.getNumber(e.getErrorCode())); } else { errorCode = ""; } while (e != null) { String p1 = mapNull(e.getSQLState(), LocalizedResource.getMessage("UT_NoSqlst")); String p2 = mapNull(e.getMessage(), LocalizedResource.getMessage("UT_NoMessa")); out.println(LocalizedResource.getMessage("UT_Error012", p1, p2, errorCode)); doTrace(out, e); e = e.getNextException(); } }
/** Calculates column display widths from the default widths of the result set. */ private static int[] getColumnDisplayWidths( ResultSetMetaData rsmd, int[] dispColumns, boolean localizedOutput) throws SQLException { int count = (dispColumns == null) ? rsmd.getColumnCount() : dispColumns.length; int[] widths = new int[count]; for (int i = 0; i < count; i++) { int colnum = (dispColumns == null) ? (i + 1) : dispColumns[i]; int dispsize = localizedOutput ? LocalizedResource.getInstance().getColumnDisplaySize(rsmd, colnum) : rsmd.getColumnDisplaySize(colnum); widths[i] = Math.min( maxWidth, Math.max( (rsmd.isNullable(colnum) == ResultSetMetaData.columnNoNulls) ? 0 : MINWIDTH, dispsize)); } return widths; }
private static void indent_DisplayCurrentRow( PrintStream out, ResultSet rs, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { Vector nestedResults; if (rs == null) { indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_NoCurreRow_19")); return; } // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; ResultSetMetaData rsmd = rs.getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); int rowLen = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); DisplayRow( out, rs, rsmd, rowLen, nestedResults, conn, indentLevel, displayColumns, displayColumnWidths); ShowWarnings(out, rs); DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; } // DisplayNextRow
static ijException driverNotClassName(String c) { return new ijException(LocalizedResource.getMessage(DriverNotClassName, c)); }
static ijException disconnectFailed() { return new ijException(LocalizedResource.getMessage(DisconnectFailed)); }
static ijException connectionGetWarningsFailed() { return new ijException(LocalizedResource.getMessage(ConnectionGetWarningsFailed)); }
static ijException classNotFound(String c) { return new ijException(LocalizedResource.getMessage(ClassNotFound, c)); }
static ijException scrollCursorsNotSupported() { return new ijException(LocalizedResource.getMessage(ScrollCursorsNotSupported)); }
private static void indent_DisplayResults( PrintWriter out, List resultSets, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { ResultSetMetaData rsmd = null; // get metadata from the first ResultSet if (resultSets != null && resultSets.size() > 0) rsmd = ((ResultSet) resultSets.get(0)).getMetaData(); checkNotNull(rsmd, "ResultSetMetaData"); Vector nestedResults; int numberOfRowsSelected = 0; // autocommit must be off or the nested cursors // are closed when the outer statement completes. if (!conn.getAutoCommit()) nestedResults = new Vector(); else nestedResults = null; if (displayColumnWidths == null) displayColumnWidths = getColumnDisplayWidths(rsmd, displayColumns, true); int len = indent_DisplayBanner(out, rsmd, indentLevel, displayColumns, displayColumnWidths); // When displaying rows, keep going past errors // unless/until the maximum # of errors is reached. int retry = 0; ResultSet rs = null; boolean doNext = true; for (int i = 0; i < resultSets.size(); i++) { rs = (ResultSet) resultSets.get(i); doNext = true; while (doNext) { try { doNext = rs.next(); if (doNext) { DisplayRow( out, rs, rsmd, len, nestedResults, conn, indentLevel, displayColumns, displayColumnWidths); ShowWarnings(out, rs); numberOfRowsSelected++; } } catch (SQLException e) { // REVISIT: might want to check the exception // and for some, not bother with the retry. if (++retry > MAX_RETRIES) throw e; else ShowSQLException(out, e); } } } if (showSelectCount == true) { if (numberOfRowsSelected == 1) { out.println(); indentedPrintLine(out, indentLevel, LocalizedResource.getMessage("UT_1RowSelec")); } else if (numberOfRowsSelected >= 0) { out.println(); indentedPrintLine( out, indentLevel, LocalizedResource.getMessage( "UT_0RowsSelec", LocalizedResource.getNumber(numberOfRowsSelected))); } } DisplayNestedResults(out, nestedResults, conn, indentLevel); nestedResults = null; }
public static ijException notJDBC20(String operation) { return new ijException(LocalizedResource.getMessage(NotJDBC20, operation)); }
static ijException illegalStatementName(String n) { return new ijException(LocalizedResource.getMessage(IllegalStatementName, n)); }
static ijException notYetImplemented() { return new ijException(LocalizedResource.getMessage(NotYetImplemented)); }
public static ijException notAvailableForDriver(String s) { return new ijException(LocalizedResource.getMessage(NotAvailableForDriver, s)); }
public static ijException zeroInvalidForAbsolute() { return new ijException(LocalizedResource.getMessage(ZeroInvalidForAbsolute)); }
static ijException waitInterrupted(Throwable t) { return new ijException(LocalizedResource.getMessage(WaitInterrupted, t.toString())); }
static ijException statementGetWarningsFailed() { return new ijException(LocalizedResource.getMessage(StatementGetWarningsFailed)); }
static ijException noUsingResults() { return new ijException(LocalizedResource.getMessage(NoUsingResults)); }
public static ijException objectWasNull(String objectName) { return new ijException(LocalizedResource.getMessage(ObjectWasNull, objectName)); }
/** * Print one row of a result set, padding each field to the display width and separating them with * '|'s * * @param out the place to write to * @param rs the ResultSet to use * @param rsmd the ResultSetMetaData to use * @param rowLen * @param nestedResults * @param conn * @param indentLevel number of tab stops to indent line * @param displayColumns A list of column numbers to display * @param displayColumnWidths If displayColumns is set, the width of columns to display, in * characters. * @exception SQLException thrown on JDBC access failure */ private static void DisplayRow( PrintWriter out, ResultSet rs, ResultSetMetaData rsmd, int rowLen, Vector nestedResults, Connection conn, int indentLevel, int[] displayColumns, int[] displayColumnWidths) throws SQLException { StringBuffer buf = new StringBuffer(); buf.ensureCapacity(rowLen); int numCols = displayColumnWidths.length; int i; // get column header info // truncate it to the column display width // add a bar between each item. for (i = 1; i <= numCols; i++) { int colnum = displayColumns == null ? i : displayColumns[i - 1]; if (i > 1) buf.append('|'); String s; switch (rsmd.getColumnType(colnum)) { default: s = LocalizedResource.getInstance().getLocalizedString(rs, rsmd, colnum); break; case Types.JAVA_OBJECT: case Types.OTHER: { Object o = rs.getObject(colnum); if (o == null) { s = "NULL"; } else if (o instanceof ResultSet && nestedResults != null) { s = LocalizedResource.getMessage( "UT_Resul0_20", LocalizedResource.getNumber(nestedResults.size())); nestedResults.addElement(o); } else { try { s = rs.getString(colnum); } catch (SQLException se) { // oops, they don't support refetching the column s = o.toString(); } } } break; } if (s == null) s = "NULL"; int w = displayColumnWidths[i - 1]; if (s.length() < w) { StringBuffer fullS = new StringBuffer(s); fullS.ensureCapacity(w); for (int k = s.length(); k < w; k++) fullS.append(' '); s = fullS.toString(); } else if (s.length() > w) // add the & marker to know it got cut off s = s.substring(0, w - 1) + "&"; buf.append(s); } indentedPrintLine(out, indentLevel, buf); } // DisplayRow
static ijException noSuchTable(String c) { return new ijException(LocalizedResource.getMessage(NoSuchTable, c)); }
static ijException alreadyHaveConnectionNamed(String n) { return new ijException(LocalizedResource.getMessage(AlreadyHaveConnectionNamed, n)); }
static ijException resultSetGetWarningsFailed() { return new ijException(LocalizedResource.getMessage(ResultSetGetWarningsFailed)); }
static { // initialize the locale support functions to default value of JVM LocalizedResource.getInstance(); }
static ijException bangException(Throwable t) { return new ijException(LocalizedResource.getMessage(BangException, t.toString())); }
static ijException classNotFoundForProtocol(String p) { return new ijException(LocalizedResource.getMessage(ClassNotFoundForProtocol, p)); }
static ijException noSuchProtocol(String c) { return new ijException(LocalizedResource.getMessage(NoSuchProtocol, c)); }