Statement execute - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:execute
 
    public static void fillSalesPeopleTable(Connection conn)
            throws SQLException { 
        Statement statement = conn.createStatement();
 
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE1);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE2);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE3);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE4);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE5);
        statement.execute(DatabaseCreator.INSERT_SALESPEOPLE6);
    } 
 
    public static void fillCustomersTable(Connection conn) throws SQLException {
        Statement statement = conn.createStatement();
 
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS1);
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS2);
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS3);
        statement.execute(DatabaseCreator.INSERT_CUSTOMERS4);
8
CodeRank
This code example shows how to use the following methods:close, x 1
 
    private void checkPoint() throws DatabaseException { 
        Statement st = null;
        try { 
            st = createStatement();
            st.execute("CALL SYSCS_UTIL.SYSCS_CHECKPOINT_DATABASE()");
        } catch (SQLException e) {
            throw new DatabaseException(e);
        } finally { 
            if (st != null) {
                try { 
                    st.close();
                } catch (SQLException e) {
                    //ok 
                } 
            } 
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:execute
 
  @Test
  public void testFindWithChildren() throws Exception {
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:association_nested", "SA", "");
    Statement stmt = conn.createStatement();
    stmt.execute("create table folder (id int, name varchar(100), parent_id int)");
 
 
    stmt.execute("insert into folder (id, name) values(1, 'Root')");
    stmt.execute("insert into folder values(2, 'Folder 1', 1)");
    stmt.execute("insert into folder values(3, 'Folder 2', 1)");
    stmt.execute("insert into folder values(4, 'Folder 2_1', 3)");
    stmt.execute("insert into folder values(5, 'Folder 2_2', 3)");
 
    /** 
     * Root/ 
     *    Folder 1/ 
     *    Folder 2/ 
     *      Folder 2_1 
     *      Folder 2_2 
7
CodeRank
This code example shows how to use the following methods:execute
	} 
 
	private static void createKeysTable(Statement s) throws SQLException {
 
		try { 
			s.execute(KEYS_TABLE);
			s.execute(KEYS_TABLE_USER_ID_INDEX);
			s.execute(KEYS_TABLE_KEY_INDEX);
			s.execute(KEYS_TABLE_USER_ID_KEY_INDEX);
			s.execute(KEYS_TABLE_LAST_SEEN_INDEX);
			System.out.println("Created table pubkeys");
		} catch (SQLException e) {
			if (e.getMessage().equals("Table 'pubkeys' already exists")) {
			} else { 
				throw e;
			} 
		} 
	} 
 
	private static void createFriendsTable(Statement s) throws SQLException {
7
CodeRank
This code example shows how to use the following methods:execute
            + "VALUES (3011, 9891.88, 10/06/1990, 2006, 1001)"; 
 
    public static void fillParentTable(Connection conn) throws SQLException {
        Statement statement = conn.createStatement();
        statement
                .execute("INSERT INTO " + PARENT_TABLE + " VALUES(1, 'test1')");
        statement.execute("INSERT INTO " + PARENT_TABLE + " VALUES(2,'test2')");
        statement
                .execute("INSERT INTO " + PARENT_TABLE + " VALUES(3, 'test3')");
    } 
 
    public static void fillFKStrictTable(Connection conn) throws SQLException {
        Statement statement = conn.createStatement();
        statement.execute("INSERT INTO " + FKSTRICT_TABLE
                + " VALUES(1, 1, '1')"); 
        statement.execute("INSERT INTO " + FKSTRICT_TABLE
                + " VALUES(2, 2, '2')"); 
        statement.execute("INSERT INTO " + FKSTRICT_TABLE
                + " VALUES(3, 1, '3')"); 
    } 
7
CodeRank
This code example shows how to use the following methods:x 1
	} 
 
	private static void createFriendsTable(Statement s) throws SQLException {
 
		try { 
			s.execute(TablesDerby.FRIENDS_TABLE);
			s.execute(FRIENDS_TABLE_UID_INDEX);
			s.execute(FRIENDS_TABLE_FID_INDEX);
			s.execute(FRIENDS_TABLE_UID_FID_INDEX);
			System.out.println("Created table friends");
		} catch (SQLException e) {
			if (e.getMessage().equals("Table/View 'FRIENDS' already exists in Schema 'PUBLICKEY'.")) {
 
			} else { 
				throw e;
			} 
		} 
	} 
} 
7
CodeRank
This code example shows how to use the following methods:close, execute
      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:execute, executeQuery
 
    private void testDuplicateOnPrimary(Connection conn) throws SQLException {
        Statement stat = conn.createStatement();
        ResultSet rs;
 
        stat.execute("CREATE TABLE table_test (\n" +
                "  id bigint(20) NOT NULL ,\n" + 
                "  a_text varchar(254) NOT NULL,\n" + 
                "  some_text varchar(254) NULL,\n" + 
                "  PRIMARY KEY (id)\n" + 
                ") ;"); 
 
        stat.execute("INSERT INTO table_test ( id, a_text, some_text ) VALUES " +
                "(1, 'aaaaaaaaaa', 'aaaaaaaaaa'), " + 
                "(2, 'bbbbbbbbbb', 'bbbbbbbbbb'), "+ 
                "(3, 'cccccccccc', 'cccccccccc'), " + 
                "(4, 'dddddddddd', 'dddddddddd'), " + 
                "(5, 'eeeeeeeeee', 'eeeeeeeeee')"); 
 
        stat.execute("INSERT INTO table_test ( id , a_text, some_text ) " +

6
CodeRank
This code example shows how to use the following methods:execute
        DeleteDbFiles.execute("data", null, true); 
        Class.forName("org.h2.Driver");
        Connection conn;
        conn = DriverManager.getConnection("jdbc:h2:data/test");
        Statement stat = conn.createStatement();
        stat.execute("create table test(id int primary key, name varchar)");
        stat.execute("insert into test values(1, 'Hello')");
        stat.execute("insert into test values(2, 'World')");
        stat.execute("create linked table test_link" +
                "('', 'jdbc:h2:data/test', '', '', 'TEST')"); 
        stat.execute("set trace_level_system_out 2");
        // the query sent to the linked database is 
        // SELECT * FROM PUBLIC.TEST T WHERE ID>=? AND ID<=? {1: 1, 2: 1}; 
        // it should also include AND NAME='Hello' 
        stat.execute("select * from test_link " +
                "where id = 1 and name = 'Hello'"); 
        conn.close();
    } 
 
} 
7
CodeRank
This code example shows how to use the following methods:execute, getResultSet
        try { 
            conn.setAutoCommit(false); 
            assertFalse(conn.getAutoCommit()); 
            String query = "select * from zoo";
            st = conn.createStatement();
            st.execute(query);
            rs = st.getResultSet();
            rsmd = rs.getMetaData();
        } catch (SQLException e) {
            fail("Couldn't get ResultSetMetaData object"); 
        } 
    } 
 
    @Override 
    public void tearDown() throws SQLException { 
        try { 
            rs.close();
            st.close();
        } catch (SQLException e) {
            fail("Couldn't close Statement object"); 
6
CodeRank
execute Method Overview
Executes the given SQL statement, which may return multiple results.
See Code Examples for other Java 8 Statement Methods: