Unanswered: Having problem with iterating throug the resultSet
I have a question on DB2 with java. Select * from mySchemaName.myTableName this is the query i am using to retrieve all the rows of the table.Now i don have any idea of the table .I dont know how many columns are there and how to retrieve the column values.
By using the following two methods ResultSetMetaData.getColumnName and ResultSetMetaData.getcolumnClassName() i am getting the column name and column data type in java.
Is there any way to get the values of the resultSet in a generic way.I mean ,to get each and every value in the result.I wanted to use ResultSet.getString() or ResultSet.getBoolean() based on the column type but before to that i have to check each and every columns data type and then use the respective methods.Is there any generic way with out checking the column data type we can retrieve the values.
I would really appreciate if some one can reply me.
I have done what you are doing, and in my experience there is no magic process that will eliminate the need to know how many columns you are dealing with and what data type each column is.
Maybe someone else has a different experience, but I doubt it. There is third party code and objects already written that will do most of the effort for you. Try looking in developerWorks on IBM's website.
Thanks a lot for your response.
I am getting each and every columns data type and checking with all java to sql data types and then getting the value.the code may some thing look like
String columntype=ResultSetMetaData..getColumnClassName(i );
String value=(String)ResultSet.getString(columnName);//like this i am checking with all java to sql data types.
Is there any good approach apart from the above code...
I would really appreciate if some one can answer this question....
if we go with ResultSet.getObject().Again we have to convert it into to some data types to retrieve the value right?
the code looks some what
I guess thsi is the way but no effective way am i correct i might be wrong though...