我试图理解PreparedStatements和CallableStatements之间的区别,但我无法理解。所以请任何人都可以将以下sql查询转换为CallableStatement。我知道如何将语句转换为PreparedStatement,但在使用CallableStatements时遇到问题。
作为java.sql.Statement
SELECT * FROM Customer WHERE customerId = 'C001'作为java.sql.PreparedStatement
SELECT * FROM Customer WHERE customerId = ? //set customerId using preparedStatement.setString(1,"C001")如何在CallableStatements中编写相同的查询
提前感谢!
发布于 2013-03-25 02:40:11
如CallableStatement API中所述
用于执行
存储过程的接口。
因此,它不能用于执行查询。
发布于 2013-03-25 02:42:02
可调用语句用于访问存储过程。
你必须在数据库中编写存储过程
为
SELECT * FROM Customer WHERE customerId = 'C001'和
请查看以下链接,以获得有关可调用语句的帮助-
1> http://www.mkyong.com/jdbc/jdbc-callablestatement-stored-procedure-out-parameter-example/
2> http://www.tutorialspoint.com/jdbc/callablestatement-object-example.htm
谢谢
发布于 2013-03-25 02:39:59
看看这个
DIfference Between Stored Procedures and Prepared Statements..?
主要用于StoredProcedure的CallableStatement
https://stackoverflow.com/questions/15602407
复制相似问题