当前位置: 技术问答>java相关
如何调用存储过程的返回值
来源: 互联网 发布时间:2015-10-23
本文导语: //stored procedure:ValidateUser //输入参数int,varchar,varchar; //输出参数int CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}"); 问题是:我怎样注册我的输出参数??? | CallableStatem...
//stored procedure:ValidateUser
//输入参数int,varchar,varchar;
//输出参数int
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}");
问题是:我怎样注册我的输出参数???
//输入参数int,varchar,varchar;
//输出参数int
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}");
问题是:我怎样注册我的输出参数???
|
CallableStatement cstmt = conn.prepareCall("{? = call ValidateUser(?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(2, uID);
cstmt.setString(3, nickname);
cstmt.setString(4, pwd);
System.out.print("Prepared sp n");
cstmt.execute();
应该是这样吧
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(2, uID);
cstmt.setString(3, nickname);
cstmt.setString(4, pwd);
System.out.print("Prepared sp n");
cstmt.execute();
应该是这样吧
|
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?,?)}");
cstmt .registerOutParameter(4,java.sql.Types.INTEGER);
cstmt .setInt(1,int1);
cstmt .setString(2,s1);
cstmt .setString(3,s1);
cstmt .registerOutParameter(4,java.sql.Types.INTEGER);
cstmt .setInt(1,int1);
cstmt .setString(2,s1);
cstmt .setString(3,s1);
|
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(1, uID);
cstmt.setString(2, nickname);
cstmt.setString(3, pwd);
System.out.print("Prepared sp n");
cstmt.execute();
System.out.print("Excuted sp n");
userID = cstmt.getInt(1);
System.out.print("Got INT(1) n");
是不是你输出参数和第一个输入参数是inout的
如果这样 呢试着用上面的看看!
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(1, uID);
cstmt.setString(2, nickname);
cstmt.setString(3, pwd);
System.out.print("Prepared sp n");
cstmt.execute();
System.out.print("Excuted sp n");
userID = cstmt.getInt(1);
System.out.print("Got INT(1) n");
是不是你输出参数和第一个输入参数是inout的
如果这样 呢试着用上面的看看!
|
按你的写法 没output的值的参数
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(1, uID);
cstmt.setString(2, nickname);
cstmt.setString(3, pwd);
System.out.print("Prepared sp n");
cstmt.execute();
这样试试会不会刚刚多了一个?
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(1, uID);
cstmt.setString(2, nickname);
cstmt.setString(3, pwd);
System.out.print("Prepared sp n");
cstmt.execute();
这样试试会不会刚刚多了一个?
|
1、调用的时候多了一个问号
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(1, uID);
cstmt.setString(2, nickname);
cstmt.setString(3, pwd);
cstmt.execute();
2、根据这个SP的名字,应当是没有结果集返回的,只是判断用户是否有效,输出在第一个inout参数里(比如返回0代表无效的账号,其它值就是代表当前合法账号了)
CallableStatement cstmt = conn.prepareCall("{call ValidateUser(?, ?, ?)}");
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.setInt(1, uID);
cstmt.setString(2, nickname);
cstmt.setString(3, pwd);
cstmt.execute();
2、根据这个SP的名字,应当是没有结果集返回的,只是判断用户是否有效,输出在第一个inout参数里(比如返回0代表无效的账号,其它值就是代表当前合法账号了)