4 Replies Latest reply: Feb 6, 2013 11:46 AM by 989312 RSS

    SQLException when calling PrepareStatement

    989312

      This is my first post and I have looked around and I can't seem to get past an issue.

      Example below.

      <code>
      PreparedStatement prepareStatement(String sql_string) throws SQLException
      {
      PreparedStatement prepared_statement = null;

      try {
      prepared_statement = dbConn.prepareStatement(sql_string, Statement.RETURN_GENERATED_KEYS);
      } catch (SQLException e) {
      checkException(e);
      }
      }
      </code>

      I am connecting to an 11.1.0.7 Oracle database and am using ojdbc6.jar (11.2 drivers I believe). Yet I continue to receive an SQLException with message (Unsupported Feature).

      Any ideas what is wrong? Has this feature been removed in the OJDBC drivers?

      Edited by: user12987060 on Feb 5, 2013 10:55 AM

        • 1. Re: SQLException when calling PrepareStatement
          EJP
          The unsupported feature will be in the SQL which you haven't shown us, or maybe it isn't an INSERT statement so asking for generated keys is futile.
          • 2. Re: SQLException when calling PrepareStatement
            989312
            EJP,

            The SQL which I'm using is this...

            INSERT INTO DMS (dms_identifier, dms_location, beacon, roadway_number, direction_code, center_id) VALUES (?,?,?,?,?,?)

            Don't think it would be causing a problem...
            • 3. Re: SQLException when calling PrepareStatement
              rp0428
              >
              I am connecting to an 11.1.0.7 Oracle database and am using ojdbc6.jar (11.2 drivers I believe). Yet I continue to receive an SQLException with message (Unsupported Feature).

              Any ideas what is wrong? Has this feature been removed in the OJDBC drivers?
              >
              No - Statement.RETURN_GENERATED_KEYS support has not been removed. It was never supported to begin with.

              See 'Retrieval of Auto_Generated Keys in the JDBC Dev guide for how, and when, to use the generated key functionality.
              http://docs.oracle.com/cd/E11882_01/java.112/e10589/jdbcvers.htm#sthref83
              >
              java.sql.Statement

              If key columns are not explicitly indicated, then Oracle JDBC drivers cannot identify which columns need to be retrieved. When a column name or column index array is used, Oracle JDBC drivers can identify which columns contain auto-generated keys that you want to retrieve. However, when the Statement.RETURN_GENERATED_KEYS integer flag is used, Oracle JDBC drivers cannot identify these columns. When the integer flag is used to indicate that auto-generated keys are to be returned, the ROWID pseudo column is returned as key. The ROWID can be then fetched from the ResultSet object and can be used to retrieve other columns.

              Sample Code
              The following code illustrates retrieval of auto-generated keys:
              . . .
              >
              Did you notice this statement: when the Statement.RETURN_GENERATED_KEYS integer flag is used, Oracle JDBC drivers cannot identify these columns?

              That citation is followed by an example of how to retrieve auto-generated keys.
              • 4. Re: SQLException when calling PrepareStatement
                989312
                This seems to have corrected the issue. Thanks for your help!