Java JDBC exec程序带有sql语句

时间:2013-05-21 12:14:06

标签: java oracle jdbc

我需要执行这个SQL代码:

exec procedure(param, param, param, param)

select * from bla_bla_table;

commit;

从此查询中获取ResultList。

我试着这样做:

CallableStatement stmt = connection.prepareCall("{call procedure(param,param,param,param)}");
stmt.execute();

如何在select * from bla_bla_table;之前插入sql语句commit以获取ResultSet。我尝试了很多方法来做到这一点......但没有任何帮助。

2 个答案:

答案 0 :(得分:4)

你试过这个吗?

connection.setAutoCommit(false); // Disable Auto Commit
CallableStatement stmt = connection.prepareCall("{call procedure(param,param,param,param)}");
stmt.execute();

Statement stmt2 = connection.createStatement();
ResultSet rs = stmt2.executeQuery("select * from bla_bla_table"); // Result set for Query

connection.commit();

答案 1 :(得分:1)

执行代码后添加此代码。

PreparedStatement prep = connection.prepareStatement(string);
ResultSet rs = prep.executeQuery();
// now iterate the resultset.

在所有事情之前,您应该确保通过将连接的autocommit选项设置为false来运行事务。

connection.setAutoCommit(false);