2

Is there any way to get ResultSet's values dynamically? here is the code below to make my question clear.

while(rsltSet.next()) { arr[i][0] = rsltSet.getInt(1)+""; arr[i][1] = rsltSet.getInt(2)+""; arr[i][2] = rsltSet.getString(3)+""; arr[i][3] = rsltSet.getString(4)+""; arr[i][4] = rsltSet.getString(5)+""; } 

I tried to use code below in a for loop, it gave me an exception which I cannot get the detail of.

for(int j=1;j<columnCount;j++) arr[i][j] = rslt2.getObject(j)+""; 

How can I get the values of ResultSet without specifyinh whether it is integer or string or date?

1
  • Why would you want to do that? You have to know what they are to ever do anything with them. I guess you could throw them into an un-typed (new word!) ArrayList, but that's a terrible idea, and you would still have to know what type they are to pull them out. Commented Nov 16, 2013 at 19:12

1 Answer 1

3

If you want the type info use the ResultSetMetaData from the ResultSet.getMetaData() call. Otherwise, you can always use getObject(j).toString().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.