当前位置: 技术问答>java相关
各位大虾,谁知道怎么通过jdbc调用sqlserver2000的存储过程
来源: 互联网 发布时间:2015-07-14
本文导语: CallableStatement cs = con.prepareCall("{call sp_dboption(?,?,?)}"); cs.setString(1,"mydb"); cs.setString(2,"recursive triggers"); cs.setString(3,"true"); boolean sc = cs.execute(); 但是sc总是false,调用不成功 3ks | 1.无参数调用方...
CallableStatement cs = con.prepareCall("{call sp_dboption(?,?,?)}");
cs.setString(1,"mydb");
cs.setString(2,"recursive triggers");
cs.setString(3,"true");
boolean sc = cs.execute();
但是sc总是false,调用不成功
3ks
cs.setString(1,"mydb");
cs.setString(2,"recursive triggers");
cs.setString(3,"true");
boolean sc = cs.execute();
但是sc总是false,调用不成功
3ks
|
1.无参数调用方式
//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure()}");
ResultSet rs = cstm.executeQuery();
2.有参数调用方式
//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure(?,?)}");
//登记输出参数,根据参数类型不同而改变java.sql.Types的值
cstm.registerOutParameter(1,java.sql.Types.TINYINT);
cstm.registerOutParameter(2,java.sql.Types.DECIMAL,2);
//执行
cstm.executeUpdate();
//获取输出参数的值
byte x = cstm.getByte(1);
Numeric n = cstm.getNumeric(2,2);
//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure()}");
ResultSet rs = cstm.executeQuery();
2.有参数调用方式
//Storeprocedure 为存储过程名
CallabelStatement cstm = con.prepareCall("{call Storeprocedure(?,?)}");
//登记输出参数,根据参数类型不同而改变java.sql.Types的值
cstm.registerOutParameter(1,java.sql.Types.TINYINT);
cstm.registerOutParameter(2,java.sql.Types.DECIMAL,2);
//执行
cstm.executeUpdate();
//获取输出参数的值
byte x = cstm.getByte(1);
Numeric n = cstm.getNumeric(2,2);