我正在尝试编写简单的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标志添加到该字符串?谢谢。 –
你为什么在意?为什么使用几个陈述是一件坏事? –