jdbc从Java调用PLSQL过程
下面是我的Java程序。我正在调用PLSQL过程来更新员工姓名。我关闭了PLSQL代码中的提交,以便可以从Java代码执行提交和回滚。但即使在我关闭自动提交并执行显式回滚之后,表中的细节仍然会更新。 怎样我不知道,请帮忙
这是我的Java代码。在PLSQL中,它只读取值并执行update语句。没有承诺
public class TestCommit {
public static void main(String[] args) throws SQLException, IOException {
CallableStatement callableStatement = null;
Connection conn = null;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager
.getConnection("jdbc:oracle:thin:testuser/testpwd@//testdb:1521/testbx");
conn.setAutoCommit(false);
String sql = "{call testpkg.saveemployee(?,?)}";
callableStatement = conn.prepareCall(sql);
callableStatement.setString("name", "spider");
callableStatement.setString("id", "A101");
callableStatement.executeQuery();
conn.rollback();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
// Close the statement
callableStatement.close();
// Close the connection
conn.close();
}
}
}
编辑:PLSQL
CREATE OR REPLACE PROCEDURE saveemployee(
name IN employee.ename%TYPE,
id IN employee.eid%TYPE)
IS
BEGIN
UPDATE employee SET ename = name WHERE eid = id;
END;
# 1 楼答案
我的错,我调用了一个错误的过程,同一个过程的两个版本在两个不同的包中, 一个有提交,另一个没有提交。我打电话给那个有承诺的人。 既然从这两个过程中都删除了提交,我的代码现在似乎可以工作了