如何在没有ResultSet的情况下获得等效的ResultSetMetaData [英] How to get equivalent of ResultSetMetaData without ResultSet
问题描述
我需要将一堆列名解析为列索引(以便使用一些不错的 ResultSetMetaData
方法)。但是,我知道如何获取 ResultSetMetaData
对象的唯一方法是在某些<$上调用 getMetaData()
c $ c> ResultSet 。
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 get a ResultSetMetaData
object is by calling getMetaData()
on some ResultSet
.
我遇到的问题是抓住一个ResultSet占据了我心中不必要的资源 - 我不知道我真的需要查询表中的数据,我只想了解一些关于该表的信息。
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.
有没有人知道如何获得 ResultSetMetaData
对象没有得到 ResultSet
(来自可能很大的表)?
Does anyone know of any way to get a ResultSetMetaData
object without getting a ResultSet
(from a potentially huge table) first?
推荐答案
也许你可以使用
DatabaseMetaData databaseMetaData = connection.getMetaData();
databaseMetaData.getColumns(null, null, tableName, "%");
每个表列返回一行。
在这种情况下,您将使用返回的 ResultSet
本身,而不是其 ResultSetMetaData
。
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.
这篇关于如何在没有ResultSet的情况下获得等效的ResultSetMetaData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!