My Oracle Support Banner

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

Last updated on AUGUST 13, 2019

Applies to:

JDBC - Version 11.1.0.7 and later
Information in this document applies to any platform.

Symptoms

On : 11.1.0.6 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.

http://download.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html#getMetaData() .

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)
  {
    System.out.println();
    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,  
  SQLException
  {

    try
    {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//hostname:port/service_name", "<username>", "<password>");
      DatabaseMetaData meta = conn.getMetaData();

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

      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");
      }
      pStmt.close();
      conn.close();

    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}


The next error is generated using the JDBC driver 11.1.0.6:

ERROR

 

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

JDBC
==============
Oracle JDBC driver: 11.1.0.6.0-Production

Connection URL
==============
jdbc:oracle:thin:@//<host_name>:<port>/<service>
java.sql.SQLException: statement handle not executed: getMetaData
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:229)
at oracle.jdbc.driver.OracleResultSetImpl.getMetaData(OracleResultSetImpl.java:141)
at oracle.jdbc.driver.OraclePreparedStatement.getMetaData(OraclePreparedStatement.java:4091)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.getMetaData(OraclePreparedStatementWrapper.java:1498)
at support.jdbc.ora.main(ora.java:40)

Changes

 

Cause

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

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


In this Document
Symptoms
 ERROR
Changes
Cause
Solution
References


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