Connection createStatement - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Connection createStatement method.

This code example shows how to use the following methods:createStatement
	public void close() throws SQLException { 
		conn.close();
	} 
 
	public ResultSet executeQuery(String sql) throws SQLException {
		Statement stat = conn.createStatement();
		ResultSet rs = stat.executeQuery(sql);
		return rs;
	} 
 
	public int executeUpdate(String sql) throws SQLException {
		Statement stat = conn.createStatement();
		int affected_num = stat.executeUpdate(sql);
 
		if (stat != null) {
			stat.close();
		} 
		return affected_num;
	} 
} 
8
CodeRank
This code example shows how to use the following methods:createStatement
 
    public void setUp() throws Exception { 
        super.setUp(); 
        Support_SQL.loadDriver(); 
        conn = Support_SQL.getConnection();
        statement = conn.createStatement();
        createTestTables(); 
 
    } 
 
    public void tearDown() throws Exception { 
        deleteTestTables(); 
        statement.close();
        conn.close();
        super.tearDown(); 
    } 
 
    public void createTestTables() { 
        try { 
            DatabaseMetaData meta = conn.getMetaData();
8
CodeRank
This code example shows how to use the following methods:createStatement
 
	  LOG.info("Executing DDL command :" + sql);
 
	  try 
	  { 
		  stmt = _bootstrapConn.createStatement();
		  int rs = stmt.executeUpdate(sql);
		  DBHelper.commit(_bootstrapConn);
		  LOG.info("Executed Commmand (" + sql + ") with result " + rs);
	  } catch (SQLException s) {
		  DBHelper.rollback(_bootstrapConn);
	  } finally { 
		  DBHelper.close(stmt);
	  } 
  } 
 
 
  public void executeUpdate(String sql)
		  throws SQLException 
  { 
7
CodeRank
This code example shows how to use the following methods:close, createStatement, prepareStatement
       ds.setDriverClassName("org.h2.Driver");
       ds.setUrl("jdbc:h2:mem:test_mem");
       ds.setAccessToUnderlyingConnectionAllowed(true);
        
       Connection conn = ds.getConnection();
       UnWrapper uw = DataSourceFinder.getUnWrapper(conn);
       assertNotNull(uw);
       assertTrue(uw.canUnwrap(conn));
       Connection unwrapped = uw.unwrap(conn);
       assertNotNull(unwrapped);
       assertTrue(unwrapped instanceof org.h2.jdbc.JdbcConnection);
        
       Statement st = conn.createStatement();
       uw = DataSourceFinder.getUnWrapper(st);
       assertNotNull(uw);
       assertTrue(uw.canUnwrap(st));
       Statement uwst = uw.unwrap(st);
       assertNotNull(uwst);
       assertTrue(uwst instanceof org.h2.jdbc.JdbcStatement);
       st.close();

7
CodeRank
This code example shows how to use the following methods:sleep, close, createStatement, getMetaData
	    try 
	    { 
	      connection = ds.getConnection();
	      System.out.println("   Got connection");
 
	      connection.getMetaData();
 
	      int leased = ds.getTotalLeased();
 
	      System.out.println("      Leased (should be 1) = " + leased);
 
	      Statement stmt = connection.createStatement();
 
	      System.out.println("      Executing statement");
	      stmt.execute("select NOW()");
	      timedOut = false;
	    } 
	    catch (Throwable t)
	    { 
	      System.err.println("Exception: " + t.getMessage());

7
CodeRank
This code example shows how to use the following methods:close, commit, createStatement, prepareStatement
        testDropCachedSeq(true); 
    } 
     
    private void testDropCachedSeq(boolean detectDeleteSeqInEval) throws Exception {
        nextConnection(); 
        conn.createStatement().execute("CREATE SEQUENCE foo.bar");
        conn.createStatement().execute("CREATE SEQUENCE bar.bas START WITH 101");
        conn.createStatement().execute("CREATE TABLE foo (k BIGINT NOT NULL PRIMARY KEY)");
         
        nextConnection(); 
        Connection conn1 = conn;
        conn = null; // So that call to nextConnection doesn't close it
         
        String stmtStr1a = "UPSERT INTO foo VALUES(NEXT VALUE FOR foo.bar)";
        PreparedStatement stmt1a = conn1.prepareStatement(stmtStr1a);
        stmt1a.execute();
        stmt1a.execute();
        String stmtStr1b = "UPSERT INTO foo VALUES(NEXT VALUE FOR bar.bas)";
        PreparedStatement stmt1b = conn1.prepareStatement(stmtStr1b);
        stmt1b.execute();

7
CodeRank
This code example shows how to use the following methods:createStatement
    public void setUp() throws Exception { 
        super.setUp(); 
        Support_SQL.loadDriver(); 
        try { 
            conn = Support_SQL.getConnection();
            statement = conn.createStatement();
            createTestTables(); 
        } catch (SQLException e) {
            fail("Unexpected SQLException " + e.toString());
        } 
        DatabaseCreator.fillParentTable(conn);
        DatabaseCreator.fillSimpleTable3(conn);
        DatabaseCreator.fillSimpleTable1(conn);
    } 
 
    public void tearDown() throws Exception { 
        deleteTestTables(); 
        statement.close();
        conn.close();
        super.tearDown(); 
7
CodeRank
This code example shows how to use the following methods:createStatement
 
   public SQLException isValidConnection(Connection c)
   { 
      try     
      { 
         Statement s = c.createStatement();
         try 
         { 
            s.execute(sql);
            return null; 
         } 
         finally 
         { 
            s.close();
         } 
      } 
      catch (SQLException e)
      { 
         return e;
      } 
7
CodeRank
This code example shows how to use the following methods:close, commit, createStatement
  } 
  @Override 
  protected void populateData(Connection conn) throws Exception {
    Statement s = null;
    try { 
      s = conn.createStatement();
      s.executeUpdate("create table dual(dual char(1) not null)");
      s.executeUpdate("insert into dual values('Y')");
      conn.commit();
    } catch (Exception e) {
      throw e;
    } finally { 
      try { 
        s.close();
      } catch (Exception ex) {}
      try { 
        conn.close();
      } catch (Exception ex) {}
    } 
  } 

7
CodeRank
This code example shows how to use the following methods:close, commit, createStatement
        try 
        { 
            c1 = myDS.getConnection();
            c2 = myDS2.getConnection();
             
            s1 = c1.createStatement();
            s2 = c2.createStatement();
             
            s1.execute("create table "+TABLE1+" ( id INTEGER, foo INTEGER )");
            s1.executeUpdate("insert into "+TABLE1+" (id, foo) values (1, 1)");
            c1.commit();
            s2.execute("create table "+TABLE2+" ( id INTEGER, foo INTEGER )");
            s2.executeUpdate("insert into "+TABLE2+" (id, foo) values (1, 1)");
            c2.commit();
             
            setupDone = true;
        } 
        finally 
        { 
            if (s1 != null) s1.close();

7
CodeRank

Related Connection createStatement Questions & Answers:

createStatement Method Overview
Creates a Statement object for sending SQL statements to the database.
See Code Examples for other Java 8 Connection Methods: