Example #1
0
 private boolean moveToNextResultsSafely(StatementScope scope, Statement stmt)
     throws SQLException {
   if (forceMultipleResultSetSupport(scope)
       || stmt.getConnection().getMetaData().supportsMultipleResultSets()) {
     return stmt.getMoreResults();
   }
   return false;
 }
 private ResultSetWrapper getNextResultSet(Statement stmt) throws SQLException {
   // Making this method tolerant of bad JDBC drivers
   try {
     if (stmt.getConnection().getMetaData().supportsMultipleResultSets()) {
       // Crazy Standard JDBC way of determining if there are more results
       if (!((!stmt.getMoreResults()) && (stmt.getUpdateCount() == -1))) {
         ResultSet rs = stmt.getResultSet();
         return rs != null ? new ResultSetWrapper(rs, configuration) : null;
       }
     }
   } catch (Exception e) {
     // Intentionally ignored.
   }
   return null;
 }
 private ResultSetWrapper getFirstResultSet(Statement stmt) throws SQLException {
   ResultSet rs = stmt.getResultSet();
   while (rs == null) {
     // move forward to get the first resultset in case the driver
     // doesn't return the resultset as the first result (HSQLDB 2.1)
     if (stmt.getMoreResults()) {
       rs = stmt.getResultSet();
     } else {
       if (stmt.getUpdateCount() == -1) {
         // no more results. Must be no resultset
         break;
       }
     }
   }
   return rs != null ? new ResultSetWrapper(rs, configuration) : null;
 }
 @Override
 protected Void execute(Connection conn) throws SQLException {
   try (Statement stmt = conn.createStatement()) {
     boolean isResultSet = stmt.execute(sql);
     // If the execute statement happens to return a result set, we should close it in case
     // the connection pool doesn't.
     if (isResultSet) {
       while (stmt.getMoreResults()) {
         try (ResultSet rs = stmt.getResultSet()) {
           // TODO: is this correct? just ignore?
         }
         ;
       }
     }
     return null;
   }
 }
 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);
   }
 }
Example #6
0
 @Override
 public boolean getMoreResults(int current) throws SQLException {
   return stat.getMoreResults(current);
 }
Example #7
0
 @Override
 public boolean getMoreResults() throws SQLException {
   return stat.getMoreResults();
 }
  public void testBatch1() throws Exception {
    Statement stmt = con.createStatement();
    String sqlwithcount1 =
        "  set nocount off "
            + "  select 'a' "
            + "  select 'b' "
            + "  create table #multi2withcountt (A VARCHAR(20)) "
            + "  insert into #multi2withcountt VALUES ('a') "
            + "  insert into #multi2withcountt VALUES ('a') "
            + "  insert into #multi2withcountt VALUES ('a') "
            + "  select 'a' "
            + "  select 'b' "
            + "  drop table #multi2withcountt";
    String sqlnocount1 =
        "  set nocount on "
            + "  select 'a' "
            + "  select 'b' "
            + "  create table #multi2nocountt (A VARCHAR(20)) "
            + "  insert into #multi2nocountt VALUES ('a') "
            + "  insert into #multi2nocountt VALUES ('a') "
            + "  insert into #multi2nocountt VALUES ('a') "
            + "  select 'a' "
            + "  select 'b' "
            + "  drop table #multi2nocountt";
    assertTrue(stmt.execute(sqlwithcount1)); // set
    ResultSet rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.getString(1).equals("a"));
    assertTrue(!rs.next());
    assertTrue(stmt.getMoreResults());
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.getString(1).equals("b"));
    assertTrue(!rs.next());
    assertTrue(!stmt.getMoreResults() && stmt.getUpdateCount() == 1);
    assertTrue(!stmt.getMoreResults() && stmt.getUpdateCount() == 1);
    assertTrue(!stmt.getMoreResults() && stmt.getUpdateCount() == 1);
    assertTrue(stmt.getMoreResults());
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(!rs.next());
    assertTrue(stmt.getMoreResults());
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(!rs.next());
    assertTrue(!stmt.getMoreResults() && stmt.getUpdateCount() == -1);

    assertTrue(stmt.execute(sqlnocount1)); // set
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.getString(1).equals("a"));
    assertTrue(!rs.next());
    assertTrue(stmt.getMoreResults());
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.getString(1).equals("b"));
    assertTrue(!rs.next());
    assertTrue(stmt.getMoreResults()); // select
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(!rs.next());
    assertTrue(stmt.getMoreResults());
    rs = stmt.getResultSet();
    assertTrue(rs.next());
    assertTrue(!rs.next());
    assertTrue(!stmt.getMoreResults() && stmt.getUpdateCount() == -1);
    stmt.close();
  }
Example #9
0
 public boolean getMoreResults() throws SQLException {
   return pst.getMoreResults();
 };