从Java调用PLSQL过程
下面是我的Java程序。 我正在调用PLSQL过程来更新Employee名称。 我关闭了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;
我的不好,我正在调用一个错误的程序,在两个不同的包中有两个版本的相同程序,一个有提交,另一个没有提交。 我打电话给那个有提交的人。 现在从两个过程中删除了提交,我的代码现在似乎正常工作。
- 在我的应用程序中获取错误“java.lang.RuntimeException:无法启动活动”
- JSP – TransformerFactory.newInstance()。newTransformer(xsl)返回null?
- NameNotFoundException:尝试仅在从Eclipse Kepler发布而不是Indigo时才查找’jdbc’
- C#和Java语法是LALR(x)吗?
- 线程:忙等待 – 空循环
- 在Java 6中,为什么即使优先级较低的线程产生,优先级较高的线程也不会运行?
- JPA没有生成“on delete set null”FK限制
- Java:通过Object(In | Out)putStreams阻塞SocketChannel上是否可以进行并发读写?
- 我可以将Eclipse设置为忽略“未处理的exception类型”
- 为什么Guava类提供了如此多的工厂方法而不是只提供varargs的方法?
- SpringBoot应用程序一直在重启(重启循环) – spring.devtools