1

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.

2 Answers 2

2

Yes. You can use a PreparedStatement and invoke its getMetadata method in order to have information about the ResultSets 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.