Package java.sql

Examples of java.sql.Statement


      Statement s = connection.createStatement();
      s.execute("delete from vw");
    }
   
    @Test public void testProcMetadataRepositoryMerge() throws Exception {
      Statement s = connection.createStatement();
      ResultSet rs = s.executeQuery("call proc(1)");
      rs.next();
      assertEquals(2011, rs.getInt(1));
    }
View Full Code Here


    @Test public void testSetProperty() throws Exception {
      CallableStatement s = connection.prepareCall("{? = call sysadmin.setProperty((select uid from tables where name='vw'), 'foo', 'bar')}");
      assertFalse(s.execute());
      assertNull(s.getClob(1));
     
      Statement stmt = connection.createStatement();
      ResultSet rs = stmt.executeQuery("select name, \"value\" from properties where uid = (select uid from tables where name='vw')");
      rs.next();
      assertEquals("foo", rs.getString(1));
      assertEquals("bar", rs.getString(2));
    }
View Full Code Here

      CallableStatement s = connection.prepareCall("{? = call sysadmin.setProperty('ah', 'foo', 'bar')}");
      s.execute();
    }
   
    @Test public void testAlterView() throws Exception {
      Statement s = connection.createStatement();
      ResultSet rs = s.executeQuery("select * from vw");
      rs.next();
      assertEquals(2011, rs.getInt(1));
     
      assertFalse(s.execute("alter view vw as select '2012'"));
     
      rs = s.executeQuery("select * from vw");
      rs.next();
      assertEquals(2012, rs.getInt(1));
    }
View Full Code Here

      rs.next();
      assertEquals(2012, rs.getInt(1));
    }
   
    @Test public void testAlterProcedure() throws Exception {
      Statement s = connection.createStatement();
      ResultSet rs = s.executeQuery("call proc(1)");
      rs.next();
      assertEquals(2011, rs.getInt(1));
     
      assertFalse(s.execute("alter procedure proc as begin select '2012'; end"));
     
      //the sleep is needed to ensure that the plan is invalidated
      Thread.sleep(100);
     
      rs = s.executeQuery("call proc(1)");
      rs.next();
      assertEquals(2012, rs.getInt(1));
    }
View Full Code Here

      rs.next();
      assertEquals(2012, rs.getInt(1));
    }
   
    @Test public void testAlterTriggerActionUpdate() throws Exception {
      Statement s = connection.createStatement();
      try {
        s.execute("update vw set x = 1");
        fail();
      } catch (SQLException e) {
      }
     
      assertFalse(s.execute("alter trigger on vw instead of update as for each row select 1;"));
     
      s.execute("update vw set x = 1");
      assertEquals(1, s.getUpdateCount());
    }
View Full Code Here

      s.execute("update vw set x = 1");
      assertEquals(1, s.getUpdateCount());
    }
   
    @Test public void testAlterTriggerActionInsert() throws Exception {
      Statement s = connection.createStatement();
      try {
        s.execute("insert into vw (x) values ('a')");
        fail();
      } catch (SQLException e) {
      }
     
      assertFalse(s.execute("alter trigger on vw instead of insert as for each row select 1;"));
     
      s.execute("insert into vw (x) values ('a')");
      assertEquals(1, s.getUpdateCount());
    }
View Full Code Here

      s.execute("insert into vw (x) values ('a')");
      assertEquals(1, s.getUpdateCount());
    }
   
    @Test public void testAlterTriggerActionDelete() throws Exception {
      Statement s = connection.createStatement();
      try {
        s.execute("delete from vw");
        fail();
      } catch (SQLException e) {
      }
     
      assertFalse(s.execute("alter trigger on vw instead of delete as for each row select 1;"));
     
      s.execute("delete from vw");
      assertEquals(1, s.getUpdateCount());
     
      assertFalse(s.execute("alter trigger on vw instead of delete disabled"));
     
      try {
        s.execute("delete from vw");
        fail();
      } catch (SQLException e) {
      }
     
      assertFalse(s.execute("alter trigger on vw instead of delete enabled"));
     
      s.execute("delete from vw");
      assertEquals(1, s.getUpdateCount());
    }
View Full Code Here

      s.execute("delete from vw");
      assertEquals(1, s.getUpdateCount());
    }
   
    @Test(expected=SQLException.class) public void testCreateTriggerActionUpdate() throws Exception {
      Statement s = connection.createStatement();
      s.execute("create trigger on vw instead of update as for each row select 1;");
    }
View Full Code Here

        if (!SysProperties.STORE_LOCAL_TIME) {
            return;
        }
        String db = "date;LOG=0;FILE_LOCK=NO";
        Connection conn = getConnection(db);
        Statement stat;
        stat = conn.createStatement();
        stat.execute("create table date_list(tz varchar, t varchar, ts timestamp)");
        conn.close();
        TimeZone defaultTimeZone = TimeZone.getDefault();
        ArrayList<TimeZone> distinct = TestDate.getDistinctTimeZones();
        try {
            for (TimeZone tz : distinct) {
                println("insert using " + tz.getID());
                TimeZone.setDefault(tz);
                DateTimeUtils.resetCalendar();
                conn = getConnection(db);
                PreparedStatement prep = conn.prepareStatement("insert into date_list values(?, ?, ?)");
                prep.setString(1, tz.getID());
                for (int m = 1; m < 10; m++) {
                    String s = "2000-0" + m + "-01 15:00:00";
                    prep.setString(2, s);
                    prep.setTimestamp(3, Timestamp.valueOf(s));
                    prep.execute();
                }
                conn.close();
            }
            printTime("inserted");
            for (TimeZone target : distinct) {
                println("select from " + target.getID());
                if ("Pacific/Kiritimati".equals(target)) {
                    // there is a problem with this time zone, but it seems
                    // unrelated to this database (possibly wrong timezone
                    // information?)
                    continue;
                }
                TimeZone.setDefault(target);
                DateTimeUtils.resetCalendar();
                conn = getConnection(db);
                stat = conn.createStatement();
                ResultSet rs = stat.executeQuery("select * from date_list order by t");
                while (rs.next()) {
                    String source = rs.getString(1);
                    String a = rs.getString(2);
                    String b = rs.getString(3);
                    b = b.substring(0, a.length());
                    if (!a.equals(b)) {
                        assertEquals(source + ">" + target, a, b);
                    }
                }
                conn.close();
            }
        } finally {
            TimeZone.setDefault(defaultTimeZone);
            DateTimeUtils.resetCalendar();
        }
        printTime("done");
        conn = getConnection(db);
        stat = conn.createStatement();
        stat.execute("drop table date_list");
        conn.close();
    }
View Full Code Here

        trace("default TransactionIsolation=" + conn.getTransactionIsolation());
        conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
        assertTrue(conn.getTransactionIsolation() == Connection.TRANSACTION_READ_COMMITTED);
        conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
        assertTrue(conn.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE);
        Statement stat = conn.createStatement();
        assertTrue(conn.getAutoCommit());
        conn.setAutoCommit(false);
        assertFalse(conn.getAutoCommit());
        conn.setAutoCommit(true);
        assertTrue(conn.getAutoCommit());
View Full Code Here

TOP

Related Classes of java.sql.Statement

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.