微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

调用存储过程并使用JDBC驱动程序注销参数

如何解决调用存储过程并使用JDBC驱动程序注销参数

我们在SNowflake中编写了一个存储过程,该过程将值插入表中并返回主键。我正在尝试使用其JDBC driver调用此存储过程。

yourList

fileName返回final Connection connection = getJdbcTemplate().getDataSource().getConnection(); final CallableStatement callableStatement = connection.prepareCall("{call REWARD.sp_issue_reward(?,?,?)}"); callableStatement.setLong(1,reward.getClientSeq()); callableStatement.setLong(2,reward.getUserUniqueId()); callableStatement.registerOutParameter(3,Types.INTEGER); // throws sqlFeatureNotSupportedException callableStatement.executeUpdate(); 的实例。问题是该类具有以下implementation for registering for output parameter

connection.prepareCall

正在使用的示例存储过程定义:

SNowflakeCallableStatementV1.class

如何使用SNowflake JDBC驱动程序获取存储过程的输出

此存储过程的结果也相同:

  /*
   The SNowflake database does not accept OUT or INOUT parameters,so the registerOutParameter functions and the get
    functions (which get values of OUT parameters) will remain not implemented)
  */
    public void registerOutParameter(int parameterIndex,int sqlType) throws sqlException {
        throw new sqlFeatureNotSupportedException();
    }

解决方法

问题在这里:

callableStatement.executeUpdate();

从JDBC调用存储过程时,没有执行更新。即使SP正在更新,您仍在执行查询。

存储过程将返回一行,其中一列返回结果。您可以像这样检索它:

Statement stmt = c.createStatement();
        
ResultSet rs = stmt.executeQuery("call TEST_JDBC()");
        
while (rs.next()) {
    System.out.println(rs.getString(1));
}

使用预备语句,您当然可以比这复杂得多,但是请使用executeQuery。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。