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(?,?)") ;
}
}
2 个解决方案
#1
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?
我的猜测是你正在使用的数据库驱动程序不支持RETURN_GENERATED_KEYS。您尝试连接的数据库是什么?
#2
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
JDBC-ODBC Bridge已过时,已从Java 8中删除。幸运的是,我们可以使用免费的开源UCanAccess JDBC驱动程序来处理Java中的Access数据库,并且UCanAccess支持RETURN_GENERATED_KEYS。有关更多信息,请参阅
Manipulating an Access database from Java without ODBC
在没有ODBC的情况下从Java操作Access数据库
#1
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?
我的猜测是你正在使用的数据库驱动程序不支持RETURN_GENERATED_KEYS。您尝试连接的数据库是什么?
#2
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
JDBC-ODBC Bridge已过时,已从Java 8中删除。幸运的是,我们可以使用免费的开源UCanAccess JDBC驱动程序来处理Java中的Access数据库,并且UCanAccess支持RETURN_GENERATED_KEYS。有关更多信息,请参阅
Manipulating an Access database from Java without ODBC
在没有ODBC的情况下从Java操作Access数据库