我在postgresql中創建了一個函數,該函數接收兩個varchar參數並返回void,它在pgadmin中執行它時正常工作,但我嘗試從它調用它時遇到問題java的。我試着用executeQuery和其他一些我發現的例子來調用函數。問題是:在java中它似乎一切正常,但是當我在postgres中檢查表時,它沒有改變,當函數應該添加一個寄存器時。 我試着用這樣的:從java調用postgres函數與JDBC不起作用
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());
}
但它仍然沒有工作...任何幫助將是巨大的。
難道是事務回滾? –
你肯定會得到一個sql異常,因爲executeQuery需要一個ResultSet,而你的sql語句是一個插入或更新。 –
看起來像MySQL語法,而不是PostgreSQL。 –