1
import java.sql.* ;
import java.util.* ;
import java.io.* ;

class DataBaseFactory{
    public static Connection getConnection() {
        // ...
    }
}

class Demo{
    public static void main(String []args) throws SQLException {
        Connection con = DataBaseFactory.getConnection() ;

        // This is throwing exception
        // PreparedStatement ps = con.prepareStatement("insert into user values(?,?)", Statement.RETURN_GENERATED_KEYS) ;

        // But this is working fine
        PreparedStatement ps = con.prepareStatement("insert into user values(?,?)") ;
    }
}
Matt
  • 14,906
  • 27
  • 99
  • 149
mogli
  • 1,549
  • 4
  • 29
  • 57
  • Dupe: http://stackoverflow.com/questions/2249600/return-generated-keys-doesnt-work-using-jdbc-odbc/2252196#2252196 – BalusC Apr 01 '10 at 11:58

2 Answers2

0

My guess would be that the database driver you're using does not support RETURN_GENERATED_KEYS. What is the database you're trying to connect to?

Yuliy
  • 17,381
  • 6
  • 41
  • 47
0

The JDBC-ODBC Bridge is obsolete and has been removed from Java 8. Fortunately, we can use the free, open-source UCanAccess JDBC driver to work with Access databases from Java, and UCanAccess supports RETURN_GENERATED_KEYS. For more information, see

Manipulating an Access database from Java without ODBC

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418