This discussion is archived
8 Replies Latest reply: Jul 18, 2007 7:58 AM by 807605 RSS

ResultSet brings unordered results on SELECT * query

807605 Newbie
Currently Being Moderated

I am querying Oracle tables and I would like the resultSet will bring the columns at the same order they were defined at the database.
I must use SELECT * on these tables for internal reasons and cannot specify the columns names instead.
Now, I am using the following standard code for that:

String query = "SELECT * FROM MYTABLE";
Connection conn = ds.getConnection();
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);

The problem is that if I go over the ResultSet object, like this:
for (int i=1 ; i<=rs.getMetaData().getColumnCount(); i++)
String col= rs.getMetaData().getColumnName(i);

I don't get the columns in the same order as defined in the database.
Any idea why and how can I force it to?