Home > Database > Mysql Tutorial > body text

mysql返回新插入的id值_MySQL

WBOY
Release: 2016-06-01 13:38:53
Original
1054 people have browsed it

bitsCN.com


mysql返回新插入的id值

 

今天项目中用到:数据表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);

}

bitsCN.com
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