0

I was trying to retrieve sequence id after immediate insert the record. I am getting java.sql.SQLException: Unsupported feature . I search and found that the issue is ojdbc14.jar is not supporting this Statement.RETURN_GENERATED_KEYS or PreparedStatement.RETURN_GENERATED_KEYS . so i replaced with ojdbc6.jar file . But still facing the same issue. Is there any workaround for this issue. Am posting the jdbc code also.

conn = DbUtils.getConnection();

          String sql = "insert into abcimages (ACCOUNT_ID, LANGUAGE_CODE, CNTR_ID, IG_CAT_ID, CP_ID, MY_GRP_ID," +
                    "FILE_TYPE_CODE, IG_NAME, IG_DESCR, START_VALID_DATE, END_VALID_DATE, IG_BIN) values (?,?,?,?,?,?,?,?,?,?,?,?)" ;
        //  PreparedStatement pstmt = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
          PreparedStatement pstmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

          pstmt.setLong(1, 1234);
          pstmt.setString(2, "ENG");
          pstmt.setLong(3, new Long(addDetails.getCntr_id()));
          pstmt.setLong(4, new Long(addDetails.getImage_cat_id()));
          pstmt.setLong(5, new Long(addDetails.getCpn_id()));
          pstmt.setString(6, null);
          pstmt.setString(7, "JPG");
          pstmt.setString(8, addDetails.getImage_name());
          pstmt.setString(9, addDetails.getImage_descr());
          pstmt.setDate(10, sqlStartDate);
          pstmt.setDate(11, sqlendDate);
          pstmt.setNull(12, java.sql.Types.BLOB);

          pstmt.executeUpdate();

          if (pstmt.executeUpdate() > 0) { 
              java.sql.ResultSet generatedKeys = pstmt.getGeneratedKeys();
              if (generatedKeys.next()) 
                  key = generatedKeys.getInt(1); 
             }


         // updateImage(imgfile, conn);
          pstmt.close();
          conn.close();
        }catch (DbConnectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "Oops ! Something Went Wrong. Please Check CWC_PROD_LOG_OUT.";
        }finally{
          DbUtils.closeConnection(conn);
        }

        return "Successfully Updated !!!";

Any help on this much appreciated.

RKCY
  • 4,095
  • 14
  • 61
  • 97
  • ojdbc14 is for Java 1.4 and ojdbc6 of Java 6 ... so how about using ojdbc7 or ojdbc8? – Tom Jul 30 '17 at 00:49
  • My current java version is 1.6. So i cannot use ojdbc7/8 versions. – RKCY Jul 30 '17 at 00:53
  • 2
    `ojdbc14` vs `ojdbc6` vs `ojdbc7` is about the Java version it is compatible with. What *driver version* are you using? 10.2.0.5? 11.1.0.7? 11.2.0.4? 12.1.0.2? 12.2.0.1? Something else? *That* is what is important for whether `RETURN_GENERATED_KEYS` is supported. Use the latest. It is compatible with earlier versions of the server. – Andreas Jul 30 '17 at 01:01
  • You don't need `new Long(...)` here. – user207421 Jul 30 '17 at 01:04
  • currently using two databases for one application. one database version is oracle 12.1.0.2.0 & 11.1.0.7.0 . The current code table "abcimages " is belongs to 12.1.0.2.0 – RKCY Jul 30 '17 at 01:06
  • I add [link to duplicate](https://stackoverflow.com/a/6084380/5221149) with correct answer, even though that answer has not been accepted: With Oracle, you need to explicitly *name* the primary key column, i.e. use the [`prepareStatement(String sql, String[] columnNames)`](https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#prepareStatement-java.lang.String-java.lang.String:A-) version of the method. Naming the column works for other RDBMS's too. – Andreas Jul 30 '17 at 01:06
  • @Andreas:- Not sure any solution in the link you have mentioned as duplicate.I tried with the solution you have mentioned , but got same excetion. – RKCY Jul 30 '17 at 01:10
  • So when you use `prepareStatement(sql, new String[] { "ABCIMAGES_ID" })` *(or whatever primary key column name is)*, it doesn't work? That's what I've always used with Oracle, and that is what linked answer shows to do. – Andreas Jul 30 '17 at 01:16
  • Yes. I tried the same . But giving the same exception – RKCY Jul 30 '17 at 01:16
  • I'm using that with a 12.1.0.2 version of `ojdbc7.jar`, and it works great. – Andreas Jul 30 '17 at 01:19
  • I cannot use ojdbc7 jar as it supports java7. but my java application is returned on java 1.6 and i cannot upgrade to 7. – RKCY Jul 30 '17 at 01:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150509/discussion-between-ravikanth-and-andreas). – RKCY Jul 30 '17 at 01:27

0 Answers0