@SuppressWarnings({"unchecked"}) public static void close(Statement statement) { log.tracef("Closing prepared statement [%s]", statement); try { // if we are unable to "clean" the prepared statement, // we do not close it try { if (statement.getMaxRows() != 0) { statement.setMaxRows(0); } if (statement.getQueryTimeout() != 0) { statement.setQueryTimeout(0); } } catch (SQLException sqle) { // there was a problem "cleaning" the prepared statement if (log.isDebugEnabled()) { log.debugf("Exception clearing maxRows/queryTimeout [%s]", sqle.getMessage()); } // EARLY EXIT!!! return; } statement.close(); } catch (SQLException e) { log.debugf("Unable to release JDBC statement [%s]", e.getMessage()); } catch (Exception e) { // try to handle general errors more elegantly log.debugf("Unable to release JDBC statement [%s]", e.getMessage()); } }
@Override public void test() throws Exception { deleteDb("resultSet"); conn = getConnection("resultSet"); stat = conn.createStatement(); testUnwrap(); testReuseSimpleResult(); testUnsupportedOperations(); testAmbiguousColumnNames(); testInsertRowWithUpdatableResultSetDefault(); testBeforeFirstAfterLast(); testParseSpecialValues(); testSubstringPrecision(); testSubstringDataType(); testColumnLabelColumnName(); testAbsolute(); testFetchSize(); testOwnUpdates(); testUpdatePrimaryKey(); testFindColumn(); testColumnLength(); testArray(); testLimitMaxRows(); trace("max rows=" + stat.getMaxRows()); stat.setMaxRows(6); trace("max rows after set to 6=" + stat.getMaxRows()); assertTrue(stat.getMaxRows() == 6); testInt(); testVarchar(); testDecimal(); testDoubleFloat(); testDatetime(); testDatetimeWithCalendar(); testBlob(); testClob(); testAutoIncrement(); conn.close(); deleteDb("resultSet"); }
public static void main(String args[]) { try { String url; if (args.length == 0) url = "jdbc:virtuoso://localhost:1111"; else url = args[0]; Class.forName("virtuoso.jdbc4.Driver"); System.out.println("--------------------- Test of the fetch execute -------------------"); System.out.print("Establish connection at " + url); Connection connection = DriverManager.getConnection(url, "dba", "dba"); if (connection instanceof virtuoso.jdbc4.VirtuosoConnection) System.out.println(" PASSED"); else { System.out.println(" FAILED"); System.exit(-1); } System.out.print("Create a Statement class attached to this connection"); Statement stmt = connection.createStatement(); if (stmt instanceof virtuoso.jdbc4.VirtuosoStatement) System.out.println(" PASSED"); else { System.out.println(" FAILED"); System.exit(-1); } System.out.print("Set fetch size attached to this statement"); stmt.setMaxRows(10); stmt.setFetchSize(10); if (stmt.getMaxRows() == 10 && stmt.getFetchSize() == 10) System.out.println(" PASSED"); else { System.out.println(" FAILED"); System.exit(-1); } System.out.println("Execute select * from INFORMATION_SCHEMA.TABLES"); boolean more = stmt.execute("select * from INFORMATION_SCHEMA.TABLES"); ResultSetMetaData data = stmt.getResultSet().getMetaData(); for (int i = 1; i <= data.getColumnCount(); i++) System.out.println(data.getColumnLabel(i) + "\t" + data.getColumnTypeName(i)); while (more) { ResultSet rs = stmt.getResultSet(); while (rs.next()) for (int i = 1; i <= data.getColumnCount(); i++) { if (i == 1 || i == 2) { String s = stmt.getResultSet().getString(i); if (stmt.getResultSet().wasNull()) System.out.print("NULL\t"); else System.out.print(s + "\t"); } } System.out.println(); more = stmt.getMoreResults(); } System.out.println(" PASSED"); System.out.print("Close statement at " + url); stmt.close(); System.out.println(" PASSED"); System.out.print("Close connection at " + url); connection.close(); System.out.println(" PASSED"); System.out.println("-------------------------------------------------------------------"); System.exit(0); } catch (Exception e) { System.out.println(" FAILED"); e.printStackTrace(); System.exit(-1); } }
@Test(expected = SQLFeatureNotSupportedException.class) public void assertGetMaxRows() throws SQLException { actual.getMaxRows(); }
@Override public int getMaxRows() throws SQLException { return stat.getMaxRows(); }
public int getMaxRows() throws SQLException { return pst.getMaxRows(); };
@Override public int getMaxRows() throws SQLException { return rawStatement.getMaxRows(); }