本文介绍了Java语句对象重用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我们是否可以重用同一Statement对象来执行多个查询.或者,我们应该为不同的查询创建新的语句.
I would like to know if we can reuse the same Statement object for executing more than one query. Or, should we create a new statement for different queries.
例如,
Connection con = getDBConnection();
Statement st1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
int i = st1.executeUpdate("update tbl_domu set domU_status=1 where domU_id=" + dom_U_id);
Statement st2 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
int j = st2.executeUpdate("insert into tbl_domU_action_history values('" + dom_U_name + "', 1, '" + date + "')");
在上述情况下,对两个executeUpdate()查询使用相同的语句st1是否有任何危害?我可以将相同的Statement对象st1用于另一个executeQuery()吗?
In the above case, is there any harm in using the same statement st1 for both the executeUpdate() queries? Can I use the same Statement object st1 for another executeQuery()?
推荐答案
我遇到了我在Javadocs中寻找的响应
I came across the response I was looking for in the Javadocs
这篇关于Java语句对象重用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!