2013-05-21 61 views
1

的Java JDBC EXEC过程我需要执行这个SQL代码:与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(); 

我如何可以插入SQL语句select * from bla_bla_table;这里commit之前得到的结果集。我尝试了很多方法来做到这一点......但没有任何帮助。

+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(); 
+0

哦,伙计,你真棒!我对JDBC有点新鲜,所以你的回答对我来说非常有用! TNX! –

1

在执行代码后添加此代码。

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

之前,你应该确保你运行一个事务,通过设置连接的自动提交选项为false。

connection.setAutoCommit(false);