Statement addBatch - 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 addBatch method.

This code example shows how to use the following methods:addBatch, executeBatch, executeUpdate
 
    @Test 
    public void multiRollback() throws SQLException { 
        ResultSet rs;
 
        stat1.executeUpdate("create table t (c1);");
        conn1.setAutoCommit(false);
        stat1.executeUpdate("insert into t values (1);");
        conn1.commit();
        stat1.executeUpdate("insert into t values (1);");
        conn1.rollback();
        stat1.addBatch("insert into t values (2);");
        stat1.addBatch("insert into t values (3);");
        stat1.executeBatch();
        conn1.commit();
        stat1.addBatch("insert into t values (7);");
        stat1.executeBatch();
        conn1.rollback();
        stat1.executeUpdate("insert into t values (4);");
        conn1.setAutoCommit(true);

6
CodeRank
This code example shows how to use the following methods:addBatch, close, executeBatch, executeQuery
    } 
 
    public void testISNullAndNot() throws SQLException{
        String sql = "create table u (c1 integer)";
        Statement st = createStatement();
        st.addBatch(sql);
        sql = "insert into u values null";
        st.addBatch(sql);
        sql = "insert into u values 1";
        st.addBatch(sql);
        sql = "insert into u values null";
        st.addBatch(sql);
        sql = "insert into u values 2";
        st.addBatch(sql);
        st.executeBatch();
 
        sql = "select * from u";
        JDBC.assertFullResultSet(st.executeQuery(sql), 
            new String[][]{
            {null}, {"1"}, {null}, {"2"}, 

6
CodeRank
This code example shows how to use the following methods:addBatch, execute, executeBatch
 
    private void testRootCause() throws SQLException {
        deleteDb("batchUpdates"); 
        conn = getConnection("batchUpdates");
        stat = conn.createStatement();
        stat.addBatch("select * from test_x");
        stat.addBatch("select * from test_y");
        try { 
            stat.executeBatch();
        } catch (SQLException e) {
            assertContains(e.toString(), "TEST_Y");
            e = e.getNextException();
            assertTrue(e != null);
            assertContains(e.toString(), "TEST_Y");
            e = e.getNextException();
            assertTrue(e != null);
            assertContains(e.toString(), "TEST_X");
            e = e.getNextException();
            assertTrue(e == null);
        } 

6
CodeRank
This code example shows how to use the following methods:addBatch, executeBatch
 
    public void tearDownData() throws Exception {
        Connection con = getDatabase().getConnection();
        con.setAutoCommit(false);
        Statement stmt = con.createStatement();
        stmt.addBatch("DROP TABLE table1");
        stmt.addBatch("DROP TABLE table2");
        stmt.addBatch("DROP TABLE table3");
        stmt.executeBatch();
        con.commit();
        con.close();
    } 
 
    public void tearDownPrecomputedTables() throws Exception {
        PrecomputedTableManager ptm = PrecomputedTableManager.getInstance(getDatabase());
        ptm.dropEverything();
    } 
 
 
    /** 
6
CodeRank
This code example shows how to use the following methods:addBatch, close, executeBatch
        try { 
            Session currentSession = getHibernateTemplate().getSessionFactory()
                    .getCurrentSession(); 
            Connection connection = currentSession.connection();
            Statement statement = connection.createStatement();
            statement.addBatch(SQL);
            statement.executeBatch();
            statement.close();
        } catch (SQLException e) {
            LOG.warn("cleaning schema", e);
        } 
    } 
 
    public void setSbcDeviceManager(SbcDeviceManager sbcDeviceManager) {
        m_sbcDeviceManager = sbcDeviceManager;
    } 
 
    public void setSbcModelSource(BeanFactoryModelSource<SbcDescriptor> sbcModelSource) {
        m_sbcModelSource = sbcModelSource;
    } 
5
CodeRank
This code example shows how to use the following methods:addBatch, execute, executeBatch
 
    private void testRootCause() throws SQLException { 
        deleteDb("batchUpdates"); 
        conn = getConnection("batchUpdates");
        stat = conn.createStatement();
        stat.addBatch("select * from test_x");
        stat.addBatch("select * from test_y");
        try { 
            stat.executeBatch();
        } catch (SQLException e) {
            assertContains(e.toString(), "TEST_Y");
            e = e.getNextException();
            assertTrue(e != null);
            assertContains(e.toString(), "TEST_Y");
            e = e.getNextException();
            assertTrue(e != null);
            assertContains(e.toString(), "TEST_X");
            e = e.getNextException();
            assertTrue(e == null);
        } 

5
CodeRank
This code example shows how to use the following methods:addBatch, clearBatch, executeBatch
 
        int updCountLength = 0;
        final String sUpdCoffee = COFFEE_UPDATE1;
        final String sInsCoffee = COFFEE_INSERT1;
        final String sDelCoffee = COFFEE_DELETE1;
        statement.addBatch(sUpdCoffee);
        statement.addBatch(sDelCoffee);
        statement.addBatch(sInsCoffee);
        statement.clearBatch();
        final int[] updateCount = statement.executeBatch();
        updCountLength = updateCount.length;
 
        assertEquals(0, updCountLength);
    } 
 
    private void testExecuteBatch01() throws SQLException { 
 
        int i = 0;
        final int[] retValue = {0, 0, 0};
        int updCountLength = 0;
5
CodeRank
This code example shows how to use the following methods:addBatch, close, executeBatch, executeQuery
     * @throws SQLException  
     */ 
    public void testNumericDataType() throws SQLException{
        String sql = "create table u (c1 int, c2 char(10))";    
        Statement st = createStatement();
        st.addBatch(sql);
        sql = "insert into u (c2) values 'asdf'";
        st.addBatch(sql);
        sql = "insert into u (c1) values null";
        st.addBatch(sql);
        sql = "insert into u (c1) values 1";
        st.addBatch(sql);
        sql = "insert into u (c1) values null";
        st.addBatch(sql);
        sql = "insert into u (c1) values 2";
        st.addBatch(sql);
        st.executeBatch();
 
        sql = "select * from u";
        String[][] result = {

6
CodeRank
This code example shows how to use the following methods:addBatch, executeBatch
			conn.setAutoCommit(false);
			StringBuilder deleteSQL = new StringBuilder();
			deleteSQL.append("Delete From T_Gdzc_Random");
			deleteSQL.append(" where 1 = 1");
			deleteSQL.append(" and card_guid = '" + card_guid + "'");
			stmt.addBatch(deleteSQL.toString());
			StringBuilder delete2SQL = new StringBuilder();
			delete2SQL.append("Delete From T_Gdzc_CheckRecord");
			delete2SQL.append(" where 1 = 1");
			delete2SQL.append(" and card_guid = '" + card_guid + "'");
			stmt.addBatch(delete2SQL.toString());
			stmt.executeBatch();
			conn.commit();
			JdbcUtil.tryClose(rs, stmt, conn);
			resultInfo.setFlag(true);
			JdbcUtil.tryClose(rs, stmt, conn);
		} catch (Exception e) {
			e.printStackTrace();
			resultInfo.setFlag(false);
			resultInfo.setMessage(e.getMessage());

5
CodeRank
This code example shows how to use the following methods:addBatch, execute, executeBatch
 
    /** Test 15 Check savepoints in batch */ 
    public void testSavepointsInBatch() throws SQLException {
        Connection con = getConnection();
        Statement s = createStatement();
        s.execute("delete from t1");
        s.addBatch("insert into t1 values(1,1)");
        s.addBatch("insert into t1 values(2,2)");
        Savepoint savepoint1 = con.setSavepoint();
        s.addBatch("insert into t1 values(3,3)");
        s.executeBatch();
        con.rollback(savepoint1);
 
        assertTableRowCount("T1", 0); 
        con.rollback();
    } 
 
    /** Test 16 grammar check for savepoint sq1 */ 
    public void testGrammarCheck() throws SQLException {
        Statement s = getConnection().createStatement();
5
CodeRank
addBatch Method Overview
Adds the given SQL command to the current list of commands for this Statement object.
See Code Examples for other Java 8 Statement Methods: