PreparedStatements或callableStatements
我试图了解PreparedStatements
和CallableStatements
之间的区别,但我无法理解。 所以任何人都可以将以下sql
Query转换为CallableStatement
。 我知道如何将Statement转换为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
编写相同的查询
提前致谢!
如CallableStatement API中所述 :
用于执行SQL存储过程的接口。
因此,它不能用于执行查询。
检查一下
存储过程与准备声明之间的差异..?
CallableStatement主要用于StoredProcedure
可调用语句用于访问存储过程。
您必须在数据库中编写存储过程
对于
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
谢谢