Z
zhuad
Unregistered / Unconfirmed
GUEST, unregistred user!
今想做个递归调用数据库的模块,由于数据连接非常耗费时间和资源,我打算用一个Connection
来解决,但这也就与多个ResultSet相关,按JDBC2的可修改结果集(ResultSet),由Statement
返回的结果集(ResultSet),是否必须有一个Statement相之对应才能进行数据库的修改?
例:(两个表用同一个Statement情况)
....
Connection connection=...
stm=connection.creatStatement(.....)
rs1=stm.executeQuery("select * from table1 ");
rs2=stm.executeQuery("select * from table2 ");
rs1.next();
rs2.next();
rs1.Update("field","value");
rs2.Update("field","value");
connection.commit();
是否正确?
rs1、rs2为同一表时又是否正确呢?
如果使用一函数来返回结果集,也就是用不同的Statement 是否可以?
例:(一个表对应一个Statement,但不在同一函数内,也不是类的元素)
....
Connection connection=...
...
ResultSet Query(String sqlString){
Statement stm=connection.createStatement(...);
return stm.executeQuery("select * from ...");
}
...
rs1=Query("select * from table1 ");
rs2=Query("select * from table2 ");
rs1.next();
rs2.next();
rs1.Update("field","value");
rs2.Update("field","value");
connection.commit();
.....
也就是ResultSet中是否自动保留Statementt 和 Connection 的实例?
来解决,但这也就与多个ResultSet相关,按JDBC2的可修改结果集(ResultSet),由Statement
返回的结果集(ResultSet),是否必须有一个Statement相之对应才能进行数据库的修改?
例:(两个表用同一个Statement情况)
....
Connection connection=...
stm=connection.creatStatement(.....)
rs1=stm.executeQuery("select * from table1 ");
rs2=stm.executeQuery("select * from table2 ");
rs1.next();
rs2.next();
rs1.Update("field","value");
rs2.Update("field","value");
connection.commit();
是否正确?
rs1、rs2为同一表时又是否正确呢?
如果使用一函数来返回结果集,也就是用不同的Statement 是否可以?
例:(一个表对应一个Statement,但不在同一函数内,也不是类的元素)
....
Connection connection=...
...
ResultSet Query(String sqlString){
Statement stm=connection.createStatement(...);
return stm.executeQuery("select * from ...");
}
...
rs1=Query("select * from table1 ");
rs2=Query("select * from table2 ");
rs1.next();
rs2.next();
rs1.Update("field","value");
rs2.Update("field","value");
connection.commit();
.....
也就是ResultSet中是否自动保留Statementt 和 Connection 的实例?