user3211403
user3211403

Reputation: 169

How do I save a resultset into a variable?

Good day, I have searched through a couple of questions in how to save the values in the resultset in a variable. Since I am using a function, I do not know what to put in the ResultSetVar.getString("") function.

Here is my query.

    sqlSelectRecord1 = "SELECT COUNT(name) as acount from maintable where VLdate = ?";
    psSelectRecord1=conn.prepareStatement(sqlSelectRecord1);
    psSelectRecord1.setString(1, strDateofVL);
    rsSelectRecord1=psSelectRecord1.executeQuery();

    String strCount;
    Integer iCount;

   while (rsSelectRecord1.next()) {
         strCount = rsSelectRecord1.getString(acount);
         iCount = Integer.valueOf(strCount);
   }

I am having an error that says acount cannot be resolved into a variable. I'm guessing it does not read my AS acount in my query. How do I make my way through this?

Upvotes: 0

Views: 731

Answers (1)

user1907906
user1907906

Reputation:

You must use a name.

strCount = rsSelectRecord1.getString("acount");

Upvotes: 2

Related Questions