如何将字符串参数中的值传递给存储过程 [英] How can I pass the values in string parameters to a stored procedure
本文介绍了如何将字符串参数中的值传递给存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
程序名称:用户
Procedure Name : Users
Parameters : @fromdate , @Todate,@Users
this is what i did try (CallableStatement s = conn.prepareCall("{CALL Users(@fromdate=?,@Todate=?,@Users=?)}")) {
s.getDate(FromDate);
s.getDate(ToDate);
s.getstring(Users)
try (ResultSet rs = s.executeQuery()) {
rs.next();
System.out.println(rs.getString("response"));
}
但它进入catchblock并提供此异常参数05/01/2017没有为存储过程用户定义。
我尝试了什么:
i试过上面的代码,但是不工作
but its going into catchblock and gives this exception Parameter 05/01/2017 was not defined for stored procedure users.
What I have tried:
i tried above code but its not working
推荐答案
这就是在java中调用参数化程序的方法
That's how calling a parametric procedure in java
import java.sql.CallableStatement;
...
//
// Prepare a call to the stored procedure 'demoSp'
// with two parameters
//
// Notice the use of JDBC-escape syntax ({call ...})
//
CallableStatement s = conn.prepareCall("{CALL Users(@fromdate=?,@Todate=?,@Users=?)}");
s.setString("1/2/2017", "2/3/2017","username");
对于整数:
For Integers:
cStmt.setInt(2, 1);
这篇关于如何将字符串参数中的值传递给存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文