我正在尝试将多个ResultSet存储到一个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");
}
感谢您的帮助!
答案 0 :(得分:2)
您的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'";