【问题标题】:PreparedStatements or callableStatementsPreparedStatements 或 callableStatements
【发布时间】:2013-03-14 04:51:24
【问题描述】:

我试图了解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中编写同样的查询

提前致谢!

【问题讨论】:

标签: java jdbc


【解决方案1】:

如CallableStatement API中所述:

用于执行 SQL 存储过程的接口。

因此,它不能用于执行查询。

【讨论】:

    【解决方案2】:

    可调用语句用于访问存储过程。

    你必须在数据库中编写存储过程

    为

    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

    谢谢

    【讨论】:

      【解决方案3】:

      检查一下

      DIfference Between Stored Procedures and Prepared Statements..?

      CallableStatement 主要用于 StoredProcedure

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-15
        • 1970-01-01
        • 2010-09-18
        • 1970-01-01
        • 2010-09-24
        • 2013-06-01
        相关资源
        最近更新 更多