-1

I'm trying to store multiple ResultSets into one ArrayList. I'm catching an error on my while-loop at the first ResultSet.

Here's my code:

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");
}

Thanks for any help!

8
  • What error? Please provide stacktrace May 8, 2015 at 16:12
  • why you start variable an method names with capitals? Hard to read and understand. May 8, 2015 at 16:14
  • 2
    I suggest you print your sql before trying to call it. It may give you a clue as to why you get errors. May 8, 2015 at 16:14
  • And I want to use the ArrayList in other areas
    – Frank
    May 8, 2015 at 16:15
  • Class name must start with capital but method and variables should be in camel case. May 8, 2015 at 16:16

1 Answer 1

2

Your SQL is malformed, you have missed some spaces:

Your first statement should be:

sql = "SELECT column";
sql += " FROM table";
sql += " WHERE col2= 'val1'";
sql += " AND col3= 'field2'";

And your second statement should be:

sql = "SELECT column";
sql += " FROM table";
sql += " WHERE col2= 'val2'";
sql += " AND col3= 'field2'";
2
  • @Frank without spaces your first query would be SELECT columnFROM tableWHERE col2= 'val1'AND col3= 'field2'
    – antonio
    May 8, 2015 at 16:28
  • Thanks, but now my arraylist only have the first resultset value...any idea what to do?
    – Frank
    May 8, 2015 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.