作者Harifucks (疝气)
看板java
标题[问题] 请问同时在同一个资料库读取多个资料表
时间Sat Aug 19 19:43:33 2006
假设我要从同一个资料库,同时得出三个资料表,请问一下最好的方法是?
方法一:
connection1 = DriverManager.getConnection(url, username, password);
statement1 = connection1.createStatement();
resultSet1 = statement1.executeQuery(sqlCmd1);
connection2 = DriverManager.getConnection(url, username, password);
statement2 = connection2.createStatement();
resultSet2 = statement2.executeQuery(sqlCmd2);
connection3 = DriverManager.getConnection(url, username, password);
statement3 = connection3.createStatement();
resultSet3 = statement3.executeQuery(sqlCmd3);
这没问题.............
方法二:
connection1 = DriverManager.getConnection(url, username, password);
statement1 = connection1.createStatement();
resultSet1 = statement1.executeQuery(sqlCmd1);
statement2 = connection1.createStatement();
resultSet2 = statement2.executeQuery(sqlCmd2);
statement3 = connection1.createStatement();
resultSet3 = statement3.executeQuery(sqlCmd3);
这我没试过...........
方法三:
connection1 = DriverManager.getConnection(url, username, password);
statement1 = connection1.createStatement();
resultSet1 = statement1.executeQuery(sqlCmd1);
resultSet2 = statement1.executeQuery(sqlCmd2);
resultSet3 = statement1.executeQuery(sqlCmd3);
这在run time有问题............
会问这样的问题是因为要考虑到变数宣告和close的问题。
到底那个方法好,谢谢。
--
台湾温泉讨论区~www.bearpipi.com.tw
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.31.142.65