I am calling a simple stored procedure simple2 in my java program i.e
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();
}
}
Here the Return Value rs should be 1 but it returns -1 why?
My stored procedure is
CREATE PROC [dbo].[simple2]
@name varchar(50), @age int
AS
set nocount on
insert into Simple1
(name,age)
values
(@name, @age)
GO
But in case of PrepareStaement it returns correct update count i.e 1 incase of my query why not with respect to callable statement?