如何用statement执行存储过程

来源:百度知道 编辑:UC知道 时间:2024/05/16 05:06:33

CallableStatement stmt=connection.prepareCall("{ call 用于更新的存储过程名称(?,?,?) }");
stmt.setString(1,"字符");
stmt.setDate(2,Date);
stmt.setDate(3,Date);
stmt.executeUpdate();
CallableStatement stmt=connection.prepareCall("{ call 用于查询过程名称(?,?,?) }");
stmt.setString(1,"字符");
stmt.setDate(2,Date);
stmt.setDate(3,Date);
stmt.executeQuery();
如果你需要传回参数,你可以这样:
CallableStatement stmt=connection.prepareCall("{ call 用于查询过程名称(?,?,?,?) }");
stmt.setString(1,"字符");
stmt.setDate(2,Date);
stmt.setDate(3,Date);
stmt.registerOutParameter(1,自己定义类型);
stmt.executeQuery();
自己定义类型 x=stmt.get自己定义类型(1);//获得传回的参数值,参数类型要自己定义的。
以下是官方文档上的原话:
public interface CallableStatementextends PreparedStatement用于执行 SQL 存储过程的接口。JDBC API 提供了一个存储过程 SQL 转义语法,该语法允许对所有 RDBMS 使用标准方式调用存储过程。此转义语法有一个包含结果参数的形式和一个不包含结果参数的形式。如果使用结果参数,则必须将其注册为 OUT 型参数。其他参数可用于输入、输出或同时用于二者。参