當前位置: 首頁>>代碼示例>>Java>>正文


Java CallableStatement.addBatch方法代碼示例

本文整理匯總了Java中java.sql.CallableStatement.addBatch方法的典型用法代碼示例。如果您正苦於以下問題:Java CallableStatement.addBatch方法的具體用法?Java CallableStatement.addBatch怎麽用?Java CallableStatement.addBatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.sql.CallableStatement的用法示例。


在下文中一共展示了CallableStatement.addBatch方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execProcBug49831

import java.sql.CallableStatement; //導入方法依賴的package包/類
private void execProcBug49831(Connection c) throws Exception {
    CallableStatement cstmt = c.prepareCall("{call pTestBug49831(?)}");
    cstmt.setObject(1, "abc", Types.VARCHAR, 32);
    cstmt.addBatch();
    cstmt.setObject(1, "def", Types.VARCHAR, 32);
    cstmt.addBatch();
    cstmt.executeBatch();
    assertEquals(2, getRowCount("testBug49831"));
    this.rs = this.stmt.executeQuery("SELECT * from testBug49831 ORDER BY VAL ASC");
    this.rs.next();
    assertEquals("abc", this.rs.getString(1));
    this.rs.next();
    assertEquals("def", this.rs.getString(1));
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:15,代碼來源:CallableStatementRegressionTest.java

示例2: shouldMeasureCallableStatement

import java.sql.CallableStatement; //導入方法依賴的package包/類
/**
 * Should measure callable statement.
 *
 * @throws SQLException
 *             the SQL exception
 */
@Test
public void shouldMeasureCallableStatement() throws SQLException {
	CallableStatement statements[] = { dataSource.getConnection().prepareCall("select"),
			dataSource.getConnection().prepareCall("select", 1, 1),
			dataSource.getConnection().prepareCall("select", 1, 1, 1) };
	for (CallableStatement statement : statements) {
		statement.execute();
		statement.executeQuery();
		statement.executeUpdate();
		statement.executeLargeUpdate();
		statement.addBatch();
		statement.executeBatch();
		statement.executeLargeBatch();
	}
	assertThat(registry.get("jdbc.Statement.Invocations", "select")).isEqualTo(1L * 6 * statements.length);
	assertThat(registry.get("jdbc.Statement.Durations", "select")).isEqualTo(123456789L * 6 * statements.length);
}
 
開發者ID:mevdschee,項目名稱:tqdev-metrics,代碼行數:24,代碼來源:InstrumentedDataSourceTest.java

示例3: executeBatchedStoredProc

import java.sql.CallableStatement; //導入方法依賴的package包/類
private void executeBatchedStoredProc(Connection c) throws Exception {
    this.stmt.executeUpdate("TRUNCATE TABLE testBatchTable");

    CallableStatement storedProc = c.prepareCall("{call testBatch(?)}");

    try {
        int numBatches = 300;

        for (int i = 0; i < numBatches; i++) {
            storedProc.setInt(1, i + 1);
            storedProc.addBatch();
        }

        int[] counts = storedProc.executeBatch();

        assertEquals(numBatches, counts.length);

        for (int i = 0; i < numBatches; i++) {
            assertEquals(1, counts[i]);
        }

        this.rs = this.stmt.executeQuery("SELECT field1 FROM testBatchTable ORDER BY field1 ASC");

        for (int i = 0; i < numBatches; i++) {
            assertTrue(this.rs.next());
            assertEquals(i + 1, this.rs.getInt(1));
        }
    } finally {

        if (storedProc != null) {
            storedProc.close();
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:35,代碼來源:CallableStatementTest.java

示例4: testBug28689

import java.sql.CallableStatement; //導入方法依賴的package包/類
/**
 * Tests fix for BUG#28689 - CallableStatement.executeBatch() doesn't work
 * when connection property "noAccessToProcedureBodies" has been set to
 * "true".
 * 
 * The fix involves changing the behavior of "noAccessToProcedureBodies", in
 * that the driver will now report all paramters as "IN" paramters but allow
 * callers to call registerOutParameter() on them.
 * 
 * @throws Exception
 */
public void testBug28689() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return; // no stored procedures
    }

    createTable("testBug28689", "(" +

            "`id` int(11) NOT NULL auto_increment,`usuario` varchar(255) default NULL,PRIMARY KEY  (`id`))");

    this.stmt.executeUpdate("INSERT INTO testBug28689 (usuario) VALUES ('AAAAAA')");

    createProcedure("sp_testBug28689", "(tid INT)\nBEGIN\nUPDATE testBug28689 SET usuario = 'BBBBBB' WHERE id = tid;\nEND");

    Connection noProcedureBodiesConn = getConnectionWithProps("noAccessToProcedureBodies=true");
    CallableStatement cStmt = null;

    try {
        cStmt = noProcedureBodiesConn.prepareCall("{CALL sp_testBug28689(?)}");
        cStmt.setInt(1, 1);
        cStmt.addBatch();
        cStmt.executeBatch();

        assertEquals("BBBBBB", getSingleIndexedValueWithQuery(noProcedureBodiesConn, 1, "SELECT `usuario` FROM testBug28689 WHERE id=1"));
    } finally {
        if (cStmt != null) {
            cStmt.close();
        }

        if (noProcedureBodiesConn != null) {
            noProcedureBodiesConn.close();
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:45,代碼來源:CallableStatementRegressionTest.java


注:本文中的java.sql.CallableStatement.addBatch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。