简体   繁体   English

带有sql语句的Java JDBC执行程序

[英]Java JDBC exec procedure with sql statement

I need to execute this SQL code: 我需要执行以下SQL代码:

exec procedure(param, param, param, param)

select * from bla_bla_table;

commit;

And get a ResultList from this query. 并从该查询中获取一个ResultList。

I tried to do it like this: 我试图这样做:

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

How can I insert sql statement select * from bla_bla_table; 如何插入sql语句select * from bla_bla_table; here before commit to get the ResultSet. commit获取ResultSet之前在这里。 I tried a lot of ways to do that... but nothing helps. 我尝试了很多方法来做到这一点……但没有任何帮助。

Did you try this? 你有尝试过吗?

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

Add this code after the execution of your code. 在执行代码后添加此代码。

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

Before everything you should make sure that you run a transaction by setting the autocommit option of the connection to false. 在进行所有操作之前,应通过将连接的autocommit选项设置为false来确保运行事务。

connection.setAutoCommit(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM