Java调用oracle function的两种方式

来源:互联网 发布:mac格式化u盘什么格式 编辑:程序博客网 时间:2024/05/22 11:38
1.PreparedStatement stmt =conn.prepareStatement("select pkg.fun(?) from dual");stmt.setLong(1,123);Result rs = stmt.executeQuery();if (rs.next) {   return rs.getDouble(1);}2.CallableStatement stmt=conn.prepareCall("{?=call pkg.fun(?)}");stmt.registerOutParameter(1,java.sql.Types.DOUBLE);stmt.setLong(2,123);if (!stmt.execute()) {   return stmt.getDouble(1);}// 下面从网上找到的信息CallableStatement.execute()返回布尔值。。如果返回的第一个值是ResultSet,则返回true,否则返回false。。终于明白为什么执行成功也返回false了。
两种方式都没问题,但是第二种方式看起来正规点。

0 0
原创粉丝点击