V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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 · 2019-07-11 11:29:18 +08:00 · 4175 次点击
    这是一个创建于 1745 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码: 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 条回复    2019-07-11 11:39:45 +08:00
    bubuXiaoqi
        1
    bubuXiaoqi  
    OP
       2019-07-11 11:39:45 +08:00
    网上查资料 说是 只有
    Statement.executeUpdate(),
    Statement.executeLargeUpdate()
    Connection.prepareStatement().

    这三个地方可以加 Statement.RETURN_GENERATED_KEYS。
    可是我不方便用预处理,但是也需要用批处理。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2758 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 14:58 · PVG 22:58 · LAX 07:58 · JFK 10:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.