I am in a situation where I need to get data from resultSet and I dont know how many columns it contains, I dont know the data types of the columns and I dont know the names of the columns. Lets say its a generic resultSet, then how will I be able to get data out of it. For example I have a function print(ResultSet rs) which prints the data in the resultSet passed to it. And I have the following 2 queries.
rs1=statement.executeQuery("Select * from Employees");
rs2=statement.executeQuery("Select name, emailId from Employees");
I need the print function to be generic for any result set.
Any ideas on that? Please correct me if I am wrong.
I don't know if you have opened another thread or not(though searched for it but didn't find it). Anyway, I have a situation where I have to search for records in a table containing a huge number of rows and the number of resulted rows is also big. So it takes a lot of time in searching through that huge table of data. So in that case what I do is that I initially search through the table and then I store the resulted rows in a temporary table. Let say the number of resulted rows are 5000 and I want to show only 15 on my page(paging/pagination). So I show the first 15 from temporary table and then on next call I get the next 15 and so on.
Now, I wanted a generic solution for this. So that I may handle any query and any resultset and based on the column types and column names in resulteSet.getMetadata(), I may make a temporary table. So thanks to Christophe that he helped me out here.