0
我打电话我的Java程序中的简单的存储过程simple2即为什么executeUpdate()方法返回-1与可调用语句,而不是更新计数或0?
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柜面我查询,为什么不针对调用语句?
http://stackoverflow.com/questions/1201358/how-can-i-get-the-number-of-records-affected-by-a-stored-procedure – guleryuz 2014-09-05 06:19:47
http:// stackoverflow可能存在重复。 COM /问题/ 12400985 /什么,做-IT-均值时,语句的executeUpdate-回报-1 – BatScream 2014-09-05 06:50:35