How to get equivalent of ResultSetMetaData without ResultSet

后端 未结 3 493
一整个雨季
一整个雨季 2021-01-03 11:12

I need to resolve a bunch of column names to column indexes (so as to use some of the nice ResultSetMetaData methods). However, the only way that I know how to

相关标签:
3条回答
  • 2021-01-03 11:34

    Another solution

    select * from mytable limit 0;

    Then the query dont get any data.

    0 讨论(0)
  • 2021-01-03 11:39

    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.

    0 讨论(0)
  • 2021-01-03 11:41

    Assuming you're doing a select * from mytable you could just add a where clause that ensures no records will be returned and the ResultSet will be empty?

    That way you are still just getting the metadata for the table you are interested in instead of the entire database.

    0 讨论(0)
提交回复
热议问题