多个查询和结果集存储在一个 ArrayList 中
Multipe Queries and ResultSets stored in one ArrayList
我正在尝试将多个结果集存储到一个 ArrayList 中。我在第一个 ResultSet 的 while 循环中发现错误。
这是我的代码:
List<String> target= new ArrayList<String>();
try{
wpCall.Connect("database");
wpCall.ResetParms();
sql = "SELECT column";
sql += "FROM table";
sql += "WHERE col2= 'val1'";
sql += "AND col3= 'field2'";
ResultSet rst1 = wpCall.GetResult(sql);
while(rst1.next()) {
String values= rst1.getString(1);
target.add(values);
}
wpCall.Connect("database");
wpCall.ResetParms();
sql = "SELECT column";
sql += "FROM table";
sql += "WHERE col2= 'val2'";
sql += "AND col3= 'field2'";
ResultSet rst1 = wpCall.GetResult(sql);
while(rst1.next()) {
String values2= rst1.getString(1);
target.add(values2);
}
}
finally {
System.out.print("Values: " + Target+ "\n");
}
感谢您的帮助!
您的 SQL 格式不正确,您遗漏了一些空格:
你的第一个声明应该是:
sql = "SELECT column";
sql += " FROM table";
sql += " WHERE col2= 'val1'";
sql += " AND col3= 'field2'";
你的第二个陈述应该是:
sql = "SELECT column";
sql += " FROM table";
sql += " WHERE col2= 'val2'";
sql += " AND col3= 'field2'";
我正在尝试将多个结果集存储到一个 ArrayList 中。我在第一个 ResultSet 的 while 循环中发现错误。
这是我的代码:
List<String> target= new ArrayList<String>();
try{
wpCall.Connect("database");
wpCall.ResetParms();
sql = "SELECT column";
sql += "FROM table";
sql += "WHERE col2= 'val1'";
sql += "AND col3= 'field2'";
ResultSet rst1 = wpCall.GetResult(sql);
while(rst1.next()) {
String values= rst1.getString(1);
target.add(values);
}
wpCall.Connect("database");
wpCall.ResetParms();
sql = "SELECT column";
sql += "FROM table";
sql += "WHERE col2= 'val2'";
sql += "AND col3= 'field2'";
ResultSet rst1 = wpCall.GetResult(sql);
while(rst1.next()) {
String values2= rst1.getString(1);
target.add(values2);
}
}
finally {
System.out.print("Values: " + Target+ "\n");
}
感谢您的帮助!
您的 SQL 格式不正确,您遗漏了一些空格:
你的第一个声明应该是:
sql = "SELECT column";
sql += " FROM table";
sql += " WHERE col2= 'val1'";
sql += " AND col3= 'field2'";
你的第二个陈述应该是:
sql = "SELECT column";
sql += " FROM table";
sql += " WHERE col2= 'val2'";
sql += " AND col3= 'field2'";