Heim > Fragen und Antworten > Hauptteil
我用的是,oracle数据库,主键是序列.
看到dbutils工具中的insert可以返回主键值,但是我试了下却报错了
public void add2() throws SQLException {
QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
String sql="INSERT INTO ACCOUNT VALUES(ACCOUNT_SEQ.NEXTVAL,?,?,SYSDATE)";
Object o=qr.insert(sql,new ScalarHandler(),"小黑",52.65);
System.out.println(o);
}
报错信息如下
Exception in thread "main" java.sql.SQLException: Wrong number of parameters: expected 3, was given 2 Query: INSERT INTO ACCOUNT VALUES(ACCOUNT_SEQ.NEXTVAL,?,?,SYSDATE) Parameters: [小黑, 52.65]
at org.apache.commons.dbutils.AbstractQueryRunner.rethrow(AbstractQueryRunner.java:392)
at org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:610)
at org.apache.commons.dbutils.QueryRunner.insert(QueryRunner.java:534)
at top.getcode.dbutils.DBUtils.QueryRunnerCRUD.add2(QueryRunnerCRUD.java:91)