[英]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.