下面是我的Java程序。我正在调用 PLSQL 过程来更新员工姓名。我关闭了 PLSQL 代码中的提交,以便可以从 Java 代码进行提交和回滚。但即使在我关闭自动提交并执行显式回滚之后,表中的详细信息仍然会更新。
如何?我不知道,请帮忙。
这是我的 Java 代码。在 PLSQL 中,它只是读取值并执行更新语句。没有提交。
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;
我的错,我调用了错误的程序,两个不同的包中有同一程序的两个版本,
一个有提交,另一个没有提交。我打电话给有承诺的人。
现在,提交已从两个过程中删除,我的代码现在似乎可以工作了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)