Home > Database > Mysql Tutorial > mysql返回新插入的id值

mysql返回新插入的id值

WBOY
Release: 2016-06-07 15:13:28
Original
1268 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 今天项目中用到:数据表id自增,当新插入一条记录后马上返回 这个插入的id值,核心代码 conn=DBUtilsC3P0.getInstance().getConnection(); Statement stmt =conn.createStatement(); stmt.executeUpdat

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  今天项目中用到:数据表id自增,当新插入一条记录后马上返回

  这个插入的id值,核心代码

  conn=DBUtilsC3P0.getInstance().getConnection();

  Statement stmt =conn.createStatement();

  stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);

  ResultSet newid = stmt.getGeneratedKeys();

  if(newid.next()){

  uid=newid.getInt(1);

  }

mysql返回新插入的id值

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template