apache commons 的dbutils如何返回新插入的主键值?

我用的是,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)

阅读 5.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题