1 posts in topic
Flat View  Flat View

Posted By:   baban_kakde
Posted On:   Monday, January 7, 2008 01:09 AM

How I can write generic method to retrive resultSet and which can be apply to any table irrespective of column name and number of column.
If someone know please give code.

Re: ResultSet

Posted By:   Robert_Lybarger  
Posted On:   Monday, January 7, 2008 09:19 PM

You write your own code. However, I'd recommend using a growable array (ArrayList, Vector, etc) to store each row-worth of data, and just using "while(resultSet.next()) { ... }" to work completely through the rows. From there, you can consult "resultSet.getMetaData()" to get a ResultSetMetaData object, which you can consult for getColumnCount, getColumnName, getColumnClassName, etc. Exactly how you pull a given column value from the row depends on what you want to accomplish. Might be getString(int) will work, and might be you'll want to use the more correct type for the column. Also, where you put the data again depends on what you need to do. If you just store each row as an Object[], then just drop the values in directly. Or you could go all the way into using some reflection to put data directly into some object's instance field based on its column name (and possibly a mapping between the two, which is up to you to figure out). In short, you've asked a fairly vague question, so you won't get a very solid answer.
About | Sitemap | Contact