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(?,?)") ;
    }
}
            Asked
            
        
        
            Active
            
        
            Viewed 1,117 times
        
    1
            
            
        - 
                    Dupe: http://stackoverflow.com/questions/2249600/return-generated-keys-doesnt-work-using-jdbc-odbc/2252196#2252196 – BalusC Apr 01 '10 at 11:58
2 Answers
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
- 
                    
- 
                    That's probably the issue (I see you also posted this on the Sun forums, and received a similar reply there). – Yuliy Jun 21 '09 at 05:48
- 
                    1There is a method to find taht out: connection.getMetaData().supportsGetGeneratedKeys() – Tim Büthe Dec 04 '09 at 15:55
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
 
    
    
        Community
        
- 1
- 1
 
    
    
        Gord Thompson
        
- 116,920
- 32
- 215
- 418
 
    