本文整理汇总了Java中java.sql.CallableStatement.executeUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java CallableStatement.executeUpdate方法的具体用法?Java CallableStatement.executeUpdate怎么用?Java CallableStatement.executeUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.sql.CallableStatement
的用法示例。
在下文中一共展示了CallableStatement.executeUpdate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug35199
import java.sql.CallableStatement; //导入方法依赖的package包/类
public void testBug35199() throws Exception {
if (!versionMeetsMinimum(5, 0)) {
return;
}
createFunction("test_function", "(a varchar(40), b bigint(20), c varchar(80)) RETURNS bigint(20) LANGUAGE SQL DETERMINISTIC "
+ "MODIFIES SQL DATA COMMENT 'bbb' BEGIN RETURN 1; END; ");
CallableStatement callable = null;
try {
callable = this.conn.prepareCall("{? = call test_function(?,101,?)}");
callable.registerOutParameter(1, Types.BIGINT);
callable.setString(2, "FOO");
callable.setString(3, "BAR");
callable.executeUpdate();
} finally {
if (callable != null) {
callable.close();
}
}
}
示例2: testBug25379
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Tests fix for BUG#25379 - INOUT parameters in CallableStatements get
* doubly-escaped.
*
* @throws Exception
* if the test fails.
*/
public void testBug25379() throws Exception {
if (!serverSupportsStoredProcedures()) {
return;
}
createTable("testBug25379", "(col char(40))");
createProcedure("sp_testBug25379", "(INOUT invalue char(255))\nBEGIN" + "\ninsert into testBug25379(col) values(invalue);\nEND");
CallableStatement cstmt = this.conn.prepareCall("{call sp_testBug25379(?)}");
cstmt.setString(1, "'john'");
cstmt.executeUpdate();
assertEquals("'john'", cstmt.getString(1));
assertEquals("'john'", getSingleValue("testBug25379", "col", "").toString());
}
示例3: 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);
}
示例4: testMoreLanceBugs
import java.sql.CallableStatement; //导入方法依赖的package包/类
public void testMoreLanceBugs() throws Exception {
if (!versionMeetsMinimum(5, 0)) {
return;
}
createTable("Bit_Tab", "( `MAX_VAL` BIT default NULL, `MIN_VAL` BIT default NULL, `NULL_VAL` BIT default NULL) DEFAULT CHARSET=latin1", "InnoDB");
// this.stmt.execute("insert into Bit_Tab values(null,0,null)");
createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT) "
+ "begin select MAX_VAL, MIN_VAL, NULL_VAL into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end ");
Boolean minBooleanVal;
Boolean oRetVal;
String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
String Min_Insert = "insert into Bit_Tab values(1,0,null)";
// System.out.println("Value to insert=" + extractVal(Min_Insert,1));
CallableStatement cstmt;
this.stmt.executeUpdate("delete from Bit_Tab");
this.stmt.executeUpdate(Min_Insert);
cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");
cstmt.registerOutParameter(1, java.sql.Types.BIT);
cstmt.registerOutParameter(2, java.sql.Types.BIT);
cstmt.registerOutParameter(3, java.sql.Types.BIT);
cstmt.executeUpdate();
boolean bRetVal = cstmt.getBoolean(2);
oRetVal = new Boolean(bRetVal);
minBooleanVal = new Boolean("false");
this.rs = this.stmt.executeQuery(Min_Val_Query);
assertEquals(minBooleanVal, oRetVal);
}
示例5: execCallUpdate
import java.sql.CallableStatement; //导入方法依赖的package包/类
public int execCallUpdate(String sql, Object[] params) throws SQLException {
CallableStatement call = conn.prepareCall(sql);
for (int i = 0; i < params.length; i++) {
call.setObject(i + 1, params[0]);
}
return call.executeUpdate();
}
示例6: testBug25715
import java.sql.CallableStatement; //导入方法依赖的package包/类
/**
* Tests fix for BUG#25715 - CallableStatements with OUT/INOUT parameters
* that are "binary" have extra 7 bytes (which happens to be the _binary
* introducer!)
*
* @throws Exception
* if the test fails.
*/
public void testBug25715() throws Exception {
if (!serverSupportsStoredProcedures()) {
return; // no stored procs
}
createProcedure("spbug25715", "(INOUT mblob MEDIUMBLOB) BEGIN SELECT 1 FROM DUAL WHERE 1=0;\nEND");
CallableStatement cstmt = null;
try {
cstmt = this.conn.prepareCall("{call spbug25715(?)}");
byte[] buf = new byte[65];
for (int i = 0; i < 65; i++) {
buf[i] = 1;
}
int il = buf.length;
int[] typesToTest = new int[] { Types.BIT, Types.BINARY, Types.BLOB, Types.JAVA_OBJECT, Types.LONGVARBINARY, Types.VARBINARY };
for (int i = 0; i < typesToTest.length; i++) {
cstmt.setBinaryStream("mblob", new ByteArrayInputStream(buf), buf.length);
cstmt.registerOutParameter("mblob", typesToTest[i]);
cstmt.executeUpdate();
InputStream is = cstmt.getBlob("mblob").getBinaryStream();
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int bytesRead = 0;
byte[] readBuf = new byte[256];
while ((bytesRead = is.read(readBuf)) != -1) {
bOut.write(readBuf, 0, bytesRead);
}
byte[] fromSelectBuf = bOut.toByteArray();
int ol = fromSelectBuf.length;
assertEquals(il, ol);
}
cstmt.close();
} finally {
if (cstmt != null) {
cstmt.close();
}
}
}
示例7: testBitSp
import java.sql.CallableStatement; //导入方法依赖的package包/类
public void testBitSp() throws Exception {
if (!versionMeetsMinimum(5, 0)) {
return;
}
createTable("`Bit_Tab`", "( `MAX_VAL` tinyint(1) default NULL, `MIN_VAL` tinyint(1) default NULL, `NULL_VAL` tinyint(1) default NULL)");
createProcedure("Bit_Proc", "(out MAX_PARAM TINYINT, out MIN_PARAM TINYINT, out NULL_PARAM TINYINT)"
+ "begin select MAX_VAL, MIN_VAL, NULL_VAL into MAX_PARAM, MIN_PARAM, NULL_PARAM from Bit_Tab; end");
Boolean minBooleanVal;
Boolean oRetVal;
String Min_Val_Query = "SELECT MIN_VAL from Bit_Tab";
//String sMaxBooleanVal = "1";
// sMaxBooleanVal = "true";
//Boolean bool = Boolean.valueOf("true");
String Min_Insert = "insert into Bit_Tab values(1,0,null)";
// System.out.println("Value to insert=" + extractVal(Min_Insert,1));
CallableStatement cstmt;
this.stmt.executeUpdate("delete from Bit_Tab");
this.stmt.executeUpdate(Min_Insert);
cstmt = this.conn.prepareCall("{call Bit_Proc(?,?,?)}");
System.out.println("register the output parameters");
cstmt.registerOutParameter(1, java.sql.Types.BIT);
cstmt.registerOutParameter(2, java.sql.Types.BIT);
cstmt.registerOutParameter(3, java.sql.Types.BIT);
System.out.println("execute the procedure");
cstmt.executeUpdate();
System.out.println("invoke getBoolean method");
boolean bRetVal = cstmt.getBoolean(2);
oRetVal = new Boolean(bRetVal);
minBooleanVal = new Boolean("false");
this.rs = this.stmt.executeQuery(Min_Val_Query);
if (oRetVal.equals(minBooleanVal)) {
System.out.println("getBoolean returns the Minimum value ");
} else {
System.out.println("getBoolean() did not return the Minimum value, getBoolean Failed!");
}
}
示例8: CallProcedure
import java.sql.CallableStatement; //导入方法依赖的package包/类
/************************************************************
* Call Procedure(One only Out Parameter)
************************************************************/
public int CallProcedure(String sql, List<CallableParameter> binds) throws Exception{
CallableStatement cStmt = null;
try{
if (conn == null) {
conn = DBCPPoolManager.getConnection(PoolName);
}
cStmt = conn.prepareCall(sql);
int retIdx = 0;
if (binds != null) {
for (int i = 1; i<= binds.size(); i++) {
if (binds.get(i - 1).getType() == CallableType.IN){
cStmt.setObject(i, binds.get(i - 1).getValue());
}else{
retIdx = i;
cStmt.registerOutParameter(i, binds.get(i - 1).getOutValueType());
}
}
}
int ret = cStmt.executeUpdate();
if (conn != null && IsTransaction == false) {
conn.commit();
}
if (retIdx != 0){
binds.get(retIdx).setValue(cStmt.getObject(retIdx));
}
return ret;
}catch(SQLException e){
LogUtils.error(CommonUtil.getStackTrace(e.getNextException()),DataAdapter.class);
throw e;
}finally {
CloseConn(cStmt);
}
}