javanix javanix - 3 months ago 7x
Java Question

How to get equivalent of ResultSetMetaData without ResultSet

I need to resolve a bunch of column names to column indexes (so as to use some of the nice

methods). However, the only way that I know how to get a
object is by calling
on some

The problem I have with that is that grabbing a ResultSet takes up uneccesary resources in my mind - I don't really need to query the data in the table, I just want some information about the table.

Does anyone know of any way to get a
object without getting a
(from a potentially huge table) first?


Maybe you could use

DatabaseMetaData databaseMetaData = connection.getMetaData();
databaseMetaData.getColumns(null, null, tableName, "%");

It returns one row for each table column.

In this case you'd use the returned ResultSet itself, not its ResultSetMetaData.

One advantage of this approach is, that it doesn't interfere with database locking and transactions.