Package java.sql

Examples of java.sql.Statement


        testNestedResultSets(conn);
        conn.close();
    }

    private void testNestedResultSets(Connection conn) throws SQLException {
        Statement stat = conn.createStatement();
        test(stat, "CREATE TABLE NEST1(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
        test(stat, "CREATE TABLE NEST2(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
        DatabaseMetaData meta = conn.getMetaData();
        ArrayList<String> result = New.arrayList();
        ResultSet rs1, rs2;
        rs1 = meta.getTables(null, null, "NEST%", null);
        while (rs1.next()) {
            String table = rs1.getString("TABLE_NAME");
            rs2 = meta.getColumns(null, null, table, null);
            while (rs2.next()) {
                String column = rs2.getString("COLUMN_NAME");
                trace("Table: " + table + " Column: " + column);
                result.add(table + "." + column);
            }
        }
        // should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME
        assertEquals(result.toString(), 4, result.size());
        result = New.arrayList();
        test(stat, "INSERT INTO NEST1 VALUES(1,'A')");
        test(stat, "INSERT INTO NEST1 VALUES(2,'B')");
        test(stat, "INSERT INTO NEST2 VALUES(1,'1')");
        test(stat, "INSERT INTO NEST2 VALUES(2,'2')");
        Statement s1 = conn.createStatement();
        Statement s2 = conn.createStatement();
        rs1 = s1.executeQuery("SELECT * FROM NEST1 ORDER BY ID");
        while (rs1.next()) {
            rs2 = s2.executeQuery("SELECT * FROM NEST2 ORDER BY ID");
            while (rs2.next()) {
                String v1 = rs1.getString("VALUE");
                String v2 = rs2.getString("VALUE");
                result.add(v1 + "/" + v2);
            }
View Full Code Here


        // nothing to do
    }

    void first() throws SQLException {
        Connection c = base.getConnection();
        Statement stat = c.createStatement();
        stat.execute("CREATE TABLE TEST (ID IDENTITY, NAME VARCHAR)");
        stat.execute("CREATE TABLE NEWS (FID NUMERIC(19) PRIMARY KEY, COMMENTS LONGVARCHAR, "
                + "LINK VARCHAR(255), STATE INTEGER, VALUE VARCHAR(255))");
        stat.execute("CREATE INDEX IF NOT EXISTS NEWS_GUID_VALUE_INDEX ON NEWS(VALUE)");
        stat.execute("CREATE INDEX IF NOT EXISTS NEWS_LINK_INDEX ON NEWS(LINK)");
        stat.execute("CREATE INDEX IF NOT EXISTS NEWS_STATE_INDEX ON NEWS(STATE)");
        PreparedStatement prep = c.prepareStatement("INSERT INTO NEWS (FID, COMMENTS, LINK, STATE, VALUE) VALUES "
                + "(?, ?, ?, ?, ?) ");
        PreparedStatement prep2 = c.prepareStatement("INSERT INTO TEST (NAME) VALUES (?)");
        for (int i = 0; i < len; i++) {
            int x = random.nextInt(10) * 128;
 
View Full Code Here

    return ds.getConnection();
  }
 
  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) {
        connection.close();
View Full Code Here

      server.deployVDB(MATVIEWS, UnitTestUtil.getTestDataPath() + "/matviews.vdb");
      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

    assertTrue(rs.next());
    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

    assertEquals("LOADED", rs.getString("loadstate"));
    assertEquals(true, rs.getBoolean("valid"));
  }
 
  @Test(expected=TeiidSQLException.class) public void testSystemMatViewsInvalidView() throws Exception {
    Statement s = conn.createStatement();
    s.execute("call refreshMatView('TEST.NotMat', false)");
  }
View Full Code Here

    }

    private void testConcurrentShutdownQuery() throws Exception {
        Connection conn1 = getConnection("multiConn");
        Connection conn2 = getConnection("multiConn");
        final Statement stat1 = conn1.createStatement();
        stat1.execute("CREATE ALIAS SLEEP FOR \"java.lang.Thread.sleep(long)\"");
        final Statement stat2 = conn2.createStatement();
        stat1.execute("SET THROTTLE 100");
        Task t = new Task() {
            public void call() throws Exception {
                stat2.executeQuery("CALL SLEEP(100)");
                Thread.sleep(10);
                stat2.executeQuery("CALL SLEEP(100)");
            }
        };
        t.execute();
        Thread.sleep(50);
        stat1.execute("SHUTDOWN");
View Full Code Here

    Statement s = conn.createStatement();
    s.execute("call refreshMatView('TEST.NotMat', false)");
  }
 
  @Test(expected=TeiidSQLException.class) public void testSystemMatViewsInvalidView1() throws Exception {
    Statement s = conn.createStatement();
    s.execute("call refreshMatView('foo', false)");
  }
View Full Code Here

    VDBMetaData vdb = server.getVDB(MATVIEWS);
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    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

        final Connection conn2 = getConnection("multiConn");
        final Connection conn3 = getConnection("multiConn");
        conn1.setAutoCommit(false);
        conn2.setAutoCommit(false);
        conn3.setAutoCommit(false);
        final Statement s1 = conn1.createStatement();
        final Statement s2 = conn2.createStatement();
        final Statement s3 = conn3.createStatement();
        s1.execute("CREATE TABLE TEST1(ID INT)");
        s2.execute("CREATE TABLE TEST2(ID INT)");
        s3.execute("CREATE TABLE TEST3(ID INT)");
        s1.execute("INSERT INTO TEST1 VALUES(1)");
        s2.execute("INSERT INTO TEST2 VALUES(2)");
        s3.execute("INSERT INTO TEST3 VALUES(3)");
        s1.execute("SET LOCK_TIMEOUT 1000");
        s2.execute("SET LOCK_TIMEOUT 1000");
        s3.execute("SET LOCK_TIMEOUT 1000");
        Thread t1 = new Thread(new Runnable() {
            public void run() {
                try {
                    s3.execute("INSERT INTO TEST2 VALUES(4)");
                    conn3.commit();
                } catch (SQLException e) {
                    TestBase.logError("insert", e);
                }
            }
View Full Code Here

TOP

Related Classes of java.sql.Statement

Copyright © 2015 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.