views:

492

answers:

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(?,?)") ;
    }
}

Thanks in advance.

A: 

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
i am using Microsoft access (Type-1 driver).
rits
That's probably the issue (I see you also posted this on the Sun forums, and received a similar reply there).
Yuliy
There is a method to find taht out: connection.getMetaData().supportsGetGeneratedKeys()
Tim Büthe