我正在嘗試編寫簡單的Java Web應用程序以從數據庫獲取數據。 我需要在不同的數據庫表上運行幾個select查詢。如何使用相同的語句和結果集運行多個select查詢?
String queryOne = "select firstname from employees where empid = id";
String queryOne = "select title from books where bookid = bid";
String queryOne = "select auther from books where bookid = bid";
而且我試圖做這樣的:
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet rs1 = statement.executeQuery(queryOne);
while (rs1.nest()) {
String firstName = rs1.getString(1);
}
statement.close();
connection.close();
我只能運行具有相同的語句一個查詢。我怎樣才能用相同的語句執行多個查詢?
可能需要幫助:http://stackoverflow.com/questions/1079 7794/multiple-queries-in-java-in-single-statement –
我得到這樣的數據源:DataSource dataSource =(DataSource)context.lookup(「jdbc/DatabaseName」);如何將allowMultipleQueries標誌添加到該字符串?謝謝。 –
你爲什麼在意?爲什麼使用幾個陳述是一件壞事? –