本文整理汇总了Java中java.sql.CallableStatement.executeBatch方法的典型用法代码示例。如果您正苦于以下问题:Java CallableStatement.executeBatch方法的具体用法?Java CallableStatement.executeBatch怎么用?Java CallableStatement.executeBatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.CallableStatement
的用法示例。
在下文中一共展示了CallableStatement.executeBatch方法的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));
}
示例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);
}
示例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();
}
}
}
示例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();
}
}
}