V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
bubuXiaoqi
V2EX  ›  MySQL

MYSQL 批处理的时候不能返回自增值?

  •  
  •   bubuXiaoqi · Jul 11, 2019 · 4996 views
    This topic created in 2486 days ago, the information mentioned may be changed or developed.

    代码: stmt = conn.createStatement(); for (String sql : sqlStr) { stmt.addBatch(sql); } stmt.executeBatch(); rs = stmt.getGeneratedKeys();

    异常: java.sql.SQLException: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate(), Statement.executeLargeUpdate() or Connection.prepareStatement().

    1 replies    2019-07-11 11:39:45 +08:00
    bubuXiaoqi
        1
    bubuXiaoqi  
    OP
       Jul 11, 2019
    网上查资料 说是 只有
    Statement.executeUpdate(),
    Statement.executeLargeUpdate()
    Connection.prepareStatement().

    这三个地方可以加 Statement.RETURN_GENERATED_KEYS。
    可是我不方便用预处理,但是也需要用批处理。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2444 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:11 · PVG 13:11 · LAX 22:11 · JFK 01:11
    ♥ Do have faith in what you're doing.