In my application I get an SQL query from user then I send to a db. Can I get information about what is the result type of SQL query is without parsing the query? I use pure JDBC to do these operations.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes. You can use a PreparedStatement
and invoke its getMetadata
method in order to have information about the ResultSet
s columns it will return.
http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html#getMetaData()
Connection conn = ...
PreparedStatement ps = conn.prepareStatement(yourStatement);
ResultSetMetadata metadata = ps.getMetadata(); // this is what you need
...
// now you can execute the query
ResultSet rs = ps.executeQuery();
回答2:
Use connection.prepareStatement()
on your query, a preparedStatement
is returned. Use its .getMetaData()
method.