[問題] 請問同時在同一個資料庫讀取多個資料表

看板java作者 (疝氣)時間19年前 (2006/08/19 19:43), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
假設我要從同一個資料庫,同時得出三個資料表,請問一下最好的方法是? 方法一: 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
文章代碼(AID): #14vlbAc0 (java)
文章代碼(AID): #14vlbAc0 (java)