My Oracle Support Banner

"java.sql.SQLException: statement handle not executed: getMetaData" While Describing A Prepared Statement (Doc ID 1383811.1)

Last updated on MARCH 08, 2017

Applies to:

JDBC - Version: and later   [Release: 11.1 and later ]
Information in this document applies to any platform.


On : version, Thin JDBC driver

The ORACLE JDBC driver will not describe a prepared statement, instead it will throw an exception statement handle not executed: getMetaData.
There does not appear to be any documentation stating that this is considered design intent by ORACLE.
The JDBC specification would suggest that the ORACLE JDBC driver is not behaving in a standard manner. .

You should be able to see this with a basic program which has the sequence

PreparedStatement pStmt = db.PrepareStatement("sql"); ResultSetMetaData rsMeta = pstmt.getMetadata().

Running the next program:

package support.jdbc;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class ora
  public static void dumpSQLException(SQLException e)
    while (e != null)
      System.out.println("Message: " + e.getMessage());
      System.out.println("SQLSTATE: " + e.getSQLState());
      System.out.println("SQL error code: " + e.getErrorCode());
      e = e.getNextException();

  public static void main(String[] args) throws ClassNotFoundException,  

      Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//hostname:port/service_name", "scott", "tiger");
      DatabaseMetaData meta = conn.getMetaData();

      // gets driver info:
      System.out.println(meta.getDriverName() + ": " +
      System.out.println("\nConnection URL\n==============");

      PreparedStatement pStmt;
      pStmt = conn.prepareStatement("select * from tab");
      ResultSetMetaData rsMeta = pStmt.getMetaData();

      int columnCount = rsMeta.getColumnCount();
      System.out.println("There are " + columnCount);

      for (int i = 0; i < columnCount; ++i)
        // This fails on the B column. Note it only happens on alter
        // of the database table when adding a new column with a default
        // and not null. If only one of each is done it works fine.
        System.out.println("Column " + (i + 1) + " or " + rsMeta.getColumnName(i + 1) + " has precision of "
+ rsMeta.getPrecision(i + 1) + " - expect 1");

    catch (Exception e)

The next error is generated using the JDBC driver


Oracle Database 10g Enterprise Edition Release - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Oracle JDBC driver:

Connection URL
java.sql.SQLException: statement handle not executed: getMetaData
at oracle.jdbc.driver.SQLStateMapping.newSQLException(
at oracle.jdbc.driver.DatabaseError.newSQLException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.DatabaseError.throwSqlException(
at oracle.jdbc.driver.OracleResultSetImpl.getMetaData(
at oracle.jdbc.driver.OraclePreparedStatement.getMetaData(
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getMetaData(
at support.jdbc.ora.main(


To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.