[英]Calling postgres function with JDBC from java doesn't work
我在postgresql中创建了一个函数,该函数接收两个varchar参数并返回void,当我在pgadmin中执行该函数时,它可以正常工作,但是尝试从Java调用它时遇到了问题。 我尝试使用executeQuery和其他一些示例调用该函数。 问题是:在Java中似乎一切正常,但是当我在postgres中检查表时,函数应该添加一个寄存器时,它没有任何变化。 我尝试了这个:
try (CallableStatement callableStatement =
dbConn.prepareCall("{ CALL prueba1(?,?) }")) {
callableStatement.setString(1,mun);
callableStatement.setString(2,edo);
callableStatement.execute();
callableStatement.close();
}
有了这个...
try (Connection conn = DBConnection.createConnection(); PreparedStatement pstmt = conn.prepareStatement("{call prueba1(?,?)}")) {
pstmt.setString(1,mun);
pstmt.setString(2,edo);
ResultSet rs = pstmt.executeQuery();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
但是它仍然无法正常工作。任何帮助都将是非常有用的。
在准备好的语句中尝试切换:
ResultSet rs = pstmt.executeQuery();
附:
pstmt.executeUpdate();
由于您的准备好的语句实际上返回的是void,因此没有要返回的结果集,它更有效地是诸如insert或update之类的指令-没有返回值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.