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

This code example shows how to use the following methods:close, executeBatch
    } 
     
    /** {@inheritDoc} */ 
    public void close(TaskAttemptContext context) throws IOException {
      try { 
        statement.executeBatch();
        connection.commit();
      } catch (SQLException e) {
        try { 
          connection.rollback();
        } 
        catch (SQLException ex) {
          LOG.warn(StringUtils.stringifyException(ex));
        } 
        throw new IOException(e.getMessage());
      } finally { 
        try { 
          statement.close();
          connection.close();
        } 

7
CodeRank
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, setInt, clearBatch, executeBatch
    private void testClearBatch01() throws SQLException { 
        trace("testClearBatch01"); 
        String sPrepStmt = COFFEE_UPDATE;
        trace("Prepared Statement String:" + sPrepStmt);
        prep = conn.prepareStatement(sPrepStmt);
        prep.setInt(1, 2);
        prep.addBatch();
        prep.setInt(1, 3);
        prep.addBatch();
        prep.setInt(1, 4);
        prep.addBatch();
        prep.clearBatch();
        assertEquals(0, prep.executeBatch().length);
    } 
 
    private void testClearBatch02() throws SQLException { 
        trace("testClearBatch02"); 
        String sUpdCoffee = COFFEE_UPDATE1;
        String sInsCoffee = COFFEE_INSERT1;
        String sDelCoffee = COFFEE_DELETE1;
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, setInt, setString, executeBatch
			conn = LocalConfig.getInstance().getCurrentConnection();
		} 
		 
		try { 
			PreparedStatement prep1 = conn.prepareStatement("update metabolites_meta_info set meta_column_name=? where id=?;");
			prep1.setString(1, columnName);
			prep1.setInt(2, id);
 
			prep1.addBatch();
 
			conn.setAutoCommit(false);
			prep1.executeBatch();
			conn.setAutoCommit(true);
			if (databaseName.compareTo("temp") != 0) {
				conn.close();
			} 
		} catch (SQLException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();			
		} 
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);
        } 

6
CodeRank
This code example shows how to use the following methods:addBatch, setString, executeBatch
			Class.forName("org.sqlite.JDBC");
		    Connection conn = DriverManager.getConnection("jdbc:sqlite:kanjidb.db");
 
		    PreparedStatement prep = conn.prepareStatement("insert into favorites (_id, state) values (?, ?);");
 
		    prep.setString(1, String.valueOf(codepoint));
		    prep.setString(2, String.valueOf(0));
		    prep.addBatch();
 
		    conn.setAutoCommit(false);
		    prep.executeBatch();
		    conn.setAutoCommit(true);
		     
		    conn.close();
		}catch(Exception e){
			e.printStackTrace();
		} 
	} 
	 
	public void testDecompress(int codepoint){
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
executeBatch Method Overview
Submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts.
See Code Examples for other Java 8 Statement Methods: