【发布时间】:2014-10-30 00:32:03
【问题描述】:
我在我的 java 程序中调用了一个简单的存储过程 simple2,即
public class Simple {
private static final String sqlSimple = " {call simple2(?,?)}";
Connection con = null;
CallableStatement cstmt=null;
public Connection getDbConnection(){
try{
Class.forName(StudentConst.getDbDriverName());
con = DriverManager.getConnection(StudentConst.getDbConnUrl(),StudentConst.getDbUser(),StudentConst.getDbPassword());
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
return con;
}
public void insertSimple(){
try{
con = getDbConnection();
cstmt = con.prepareCall(sqlSimple);
cstmt.setString(1,"naveen");
cstmt.setInt(2, 22);
int rs = cstmt.executeUpdate();
System.out.println("return val is "+rs);
}catch(SQLException e){
System.out.println("caught"+e);
}
}
public static void main(String[] args) {
Simple s = new Simple();
s.insertSimple();
}
}
这里的返回值 rs 应该是 1 但它返回 -1 为什么?
我的存储过程是
CREATE PROC [dbo].[simple2]
@name varchar(50), @age int
AS
set nocount on
insert into Simple1
(name,age)
values
(@name, @age)
GO
但在 PrepareStaement 的情况下,它返回正确的更新计数,即 1 在我的查询中,为什么不考虑可调用语句?
【问题讨论】:
标签: java sql-server-2008