Is it possible to call find the number of columns in a JDBC query without executing it?
From: Geoff Hardy (geoffhardynzNONE_at_hotmail.com)
Date: 02/18/04
- Previous message: Jay Grubb: "Re: Java Stored Procedures"
- Next in thread: Chris Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: Chris Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: David Harper: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: Joe Weinstein: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: Sampsa Sohlman: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Feb 2004 14:52:20 -0800
Is it possible to call find the number of columns in a query without
executing it?
I am using the Oracle JDBC thin client driver and I have a number of
queries for which I would like to find out how many columns are being
selected.
For example, if given "select a, b, from atable" there are two columns
being selected.
Executing the queries is likely to be expensive so I want to avoid
that. I tried using the following code:
PreparedStatement preparedStatement =
connection.prepareStatement(queryStatement);
long columnCount = preparedStatement.getMetaData().getColumnCount();
This causes the following exception:
java.sql.SQLException: statement handle not executed: getMetaData
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
at oracle.jdbc.driver.OracleResultSetImpl.getMetaData(OracleResultSetImpl.java:160)
at oracle.jdbc.driver.OraclePreparedStatement.getMetaData(OraclePreparedStatement.java:1137)
If I call execute before calling getMetaData, this exception is not
caused, but I would like to avoid calling execute if possible!
Thanks in advance for any help!
- Previous message: Jay Grubb: "Re: Java Stored Procedures"
- Next in thread: Chris Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: Chris Smith: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: David Harper: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: Joe Weinstein: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Reply: Sampsa Sohlman: "Re: Is it possible to call find the number of columns in a JDBC query without executing it?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|