Package java.sql

Examples of java.sql.ResultSet


        c.close();
    }

    void finalTest() throws SQLException {
        conn = base.getConnection();
        ResultSet rs = conn.createStatement().executeQuery("select count(*) from customer");
        rs.next();
        base.assertEquals(customerCount, rs.getInt(1));
        // System.out.println("customers: " + rs.getInt(1));

        rs = conn.createStatement().executeQuery("select count(*) from orders");
        rs.next();
        base.assertEquals(orderCount, rs.getInt(1));
        // System.out.println("orders: " + rs.getInt(1));

        rs = conn.createStatement().executeQuery("select count(*) from orderLine");
        rs.next();
        base.assertEquals(orderLineCount, rs.getInt(1));
        // System.out.println("orderLines: " + rs.getInt(1));

        conn.close();
    }
View Full Code Here


                    prep = conn.prepareStatement("SELECT * FROM NEWS WHERE LINK = ?");
                } else {
                    prep = conn.prepareStatement("SELECT * FROM NEWS WHERE VALUE = ?");
                }
                prep.setString(1, PREFIX_URL + random.nextInt(len));
                ResultSet rs = prep.executeQuery();
                if (!rs.next()) {
                    throw new SQLException("expected one row, got none");
                }
                if (rs.next()) {
                    throw new SQLException("expected one row, got more");
                }
            } else {
                PreparedStatement prep = conn.prepareStatement("UPDATE NEWS SET STATE = ? WHERE FID = ?");
                prep.setInt(1, random.nextInt(100));
View Full Code Here

 
  public static void execute(Connection connection, String sql) throws Exception {
    try {
      Statement statement = connection.createStatement();
     
      ResultSet results = statement.executeQuery(sql);
     
      ResultSetMetaData metadata = results.getMetaData();
      int columns = metadata.getColumnCount();
      System.out.println("Results");
      for (int row = 1; results.next(); row++) {
        System.out.print(row + ": ");
        for (int i = 0; i < columns; i++) {
          if (i > 0) {
            System.out.print(",");
          }
          System.out.print(results.getString(i+1));
        }
        System.out.println();
      }
      System.out.println("Query Plan");
      System.out.println(statement.unwrap(TeiidStatement.class).getPlanDescription());
     
      results.close();
      statement.close();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      if (connection != null) {
View Full Code Here

        restart();
        prep.setString(1, "World");
        restart();
        prep.execute();
        restart();
        ResultSet rs = stat.executeQuery("select * from test order by id");
        restart();
        assertTrue(rs.next());
        restart();
        assertEquals(1, rs.getInt(1));
        restart();
        assertEquals("Hello", rs.getString(2));
        restart();
        assertTrue(rs.next());
        restart();
        assertEquals(2, rs.getInt(1));
        restart();
        assertEquals("World", rs.getString(2));
        restart();
        assertFalse(rs.next());
        restart();
        stat.execute("SET @TEST 10");
        restart();
        rs = stat.executeQuery("CALL @TEST");
        rs.next();
        assertEquals(10, rs.getInt(1));
        stat.setFetchSize(10);
        restart();
        rs = stat.executeQuery("select * from system_range(1, 20)");
        restart();
        for (int i = 0;; i++) {
            try {
                boolean more = rs.next();
                if (!more) {
                    assertEquals(i, 20);
                    break;
                }
                restart();
                int x = rs.getInt(1);
                assertEquals(x, i + 1);
                if (i > 10) {
                    fail();
                }
            } catch (SQLException e) {
                if (i < 10) {
                    throw e;
                }
            }
        }
        restart();
        rs.close();

        conn.setAutoCommit(false);
        restart();
        assertThrows(ErrorCode.CONNECTION_BROKEN_1, conn.createStatement()).
                execute("select * from test");
View Full Code Here

            }
        }
    }

    private boolean containsTempTables() throws SQLException {
        ResultSet rs = conn.getMetaData().getTables(null, null, null, new String[] { "TABLE" });
        while (rs.next()) {
            String sql = rs.getString("SQL");
            if (sql != null) {
                if (sql.indexOf("TEMPORARY") >= 0) {
                    return true;
                }
            }
View Full Code Here

      conn = server.createConnection("jdbc:teiid:matviews");
    }
 
  @Test public void testSystemMatViewsWithImplicitLoad() throws Exception {
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select * from MatViews order by name");
    assertTrue(rs.next());
    assertEquals("NEEDS_LOADING", rs.getString("loadstate"));
    assertEquals("#MAT_TEST.ERRORVIEW", rs.getString("targetName"));
    assertTrue(rs.next());
    assertEquals("NEEDS_LOADING", rs.getString("loadstate"));
    assertEquals("#MAT_TEST.MATVIEW", rs.getString("targetName"));
    assertTrue(rs.next());
    assertEquals(false, rs.getBoolean("valid"));
    assertEquals("#MAT_TEST.RANDOMVIEW", rs.getString("targetName"));
    rs = s.executeQuery("select * from MatView");
    assertTrue(rs.next());
    rs = s.executeQuery("select * from MatViews where name = 'MatView'");
    assertTrue(rs.next());
    assertEquals("LOADED", rs.getString("loadstate"));
    try {
      s.executeQuery("select * from ErrorView");
    } catch (SQLException e) {
     
    }
    rs = s.executeQuery("select * from MatViews where name = 'ErrorView'");
    assertTrue(rs.next());
    assertEquals("FAILED_LOAD", rs.getString("loadstate"));
  }
View Full Code Here

    assertEquals("FAILED_LOAD", rs.getString("loadstate"));
  }
 
  @Test public void testSystemMatViewsWithExplicitRefresh() throws Exception {
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("select * from (call refreshMatView('TEST.MATVIEW', false)) p");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    rs = s.executeQuery("select * from MatViews where name = 'MatView'");
    assertTrue(rs.next());
    assertEquals("LOADED", rs.getString("loadstate"));
    assertEquals(true, rs.getBoolean("valid"));
  }
View Full Code Here

    Table t = tm.getGroupID("TEST.RANDOMVIEW");
    t.setSelectTransformation("/*+ cache(updatable) */ " +  t.getSelectTransformation());
   
    Statement s = conn.createStatement();
    //prior to load refresh of a single row returns -1
    ResultSet rs = s.executeQuery("select * from (call refreshMatViewRow('TEST.RANDOMVIEW', 0)) p");
    assertTrue(rs.next());
    assertEquals(-1, rs.getInt(1));
    assertFalse(rs.next());
   
    rs = s.executeQuery("select * from (call refreshMatView('TEST.RANDOMVIEW', false)) p");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    rs = s.executeQuery("select * from MatViews where name = 'RandomView'");
    assertTrue(rs.next());
    assertEquals("LOADED", rs.getString("loadstate"));
    assertEquals(true, rs.getBoolean("valid"));
    rs = s.executeQuery("select x from TEST.RANDOMVIEW");
    assertTrue(rs.next());
    double key = rs.getDouble(1);
   
    rs = s.executeQuery("select * from (call refreshMatViewRow('TEST.RANDOMVIEW', "+key+")) p");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1)); //1 row updated (removed)
   
    rs = s.executeQuery("select * from TEST.RANDOMVIEW");
    assertFalse(rs.next());
   
    rs = s.executeQuery("select * from (call refreshMatViewRow('TEST.RANDOMVIEW', "+key+")) p");
    assertTrue(rs.next());
    assertEquals(0, rs.getInt(1)); //no rows updated
  }
View Full Code Here

    if (quoteString != null && quoteString.trim().length() == 0) {
      quoteString = null;
    }
   
    if (widenUnsingedTypes) {
      ResultSet rs = metadata.getTypeInfo();
      while (rs.next()) {
        String name = rs.getString(1);
        boolean unsigned = rs.getBoolean(10);
        if (unsigned) {
          unsignedTypes.add(name);
        }
      }
    }
View Full Code Here

  }

  private void getProcedures(MetadataFactory metadataFactory,
      DatabaseMetaData metadata) throws SQLException, TranslatorException {
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, "JDBCMetadataProcessor - Importing procedures"); //$NON-NLS-1$
    ResultSet procedures = metadata.getProcedures(catalog, schemaPattern, procedureNamePattern);
    int rsColumns = procedures.getMetaData().getColumnCount();
    while (procedures.next()) {
      String procedureCatalog = procedures.getString(1);
      String procedureSchema = procedures.getString(2);
      String procedureName = procedures.getString(3);
      String nameInSource = procedureName;
      if (useProcedureSpecificName && rsColumns >= 9) {
        procedureName = procedures.getString(9);
        if (procedureName == null) {
          procedureName = nameInSource;
        }
      }
      String fullProcedureName = getFullyQualifiedName(procedureCatalog, procedureSchema, procedureName);
      Procedure procedure = metadataFactory.addProcedure(useFullSchemaName?fullProcedureName:procedureName);
      procedure.setNameInSource(getFullyQualifiedName(procedureCatalog, procedureSchema, nameInSource, true));
      ResultSet columns = metadata.getProcedureColumns(catalog, procedureSchema, procedureName, null);
      while (columns.next()) {
        String columnName = columns.getString(4);
        short columnType = columns.getShort(5);
        int sqlType = columns.getInt(6);
        String typeName = columns.getString(7);
        sqlType = checkForUnsigned(sqlType, typeName);
        if (columnType == DatabaseMetaData.procedureColumnUnknown) {
          continue; //there's a good chance this won't work
        }
        BaseColumn record = null;
        int precision = columns.getInt(8);
        String runtimeType = getRuntimeType(sqlType, typeName, precision);
        if (columnType == DatabaseMetaData.procedureColumnResult) {
          Column column = metadataFactory.addProcedureResultSetColumn(columnName, runtimeType, procedure);
          record = column;
          column.setNativeType(typeName);
        } else {
          record = metadataFactory.addProcedureParameter(columnName, runtimeType, Type.values()[columnType], procedure);
        }
        record.setPrecision(columns.getInt(8));
        record.setLength(columns.getInt(9));
        record.setScale(columns.getInt(10));
        record.setRadix(columns.getInt(11));
        record.setNullType(NullType.values()[columns.getShort(12)]);
        record.setAnnotation(columns.getString(13));
      }
    }
    procedures.close();
  }
View Full Code Here

TOP

Related Classes of java.sql.ResultSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.