Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java obtains mysql self-increment id

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Option 1:

Statement.executeUpdate ("sql", Statement.RETURN_GENERATED_KEYS)

Resultset = statement.getGeneratedKeys ()

If (resultset! = null & & resultset.next ()) {

Generatedkey = resultset.getLong (1); / / returns the inserted primary key id

Option 2:

Insert into test (test_name) values ('111')

Select last_insert_id ()

The two schemes need to be tested and have not yet been tested.

(test results on 2006-07-06:

The former scheme is more general, but needs jdbc3.0 support.

The latter scheme: only for mysql

The latter scheme sqlserver uses select @ @ identity

)

Http://kb.csdn.net/java/Articles/200605/485033bf-2d4c-4cea-9f79-fc714f02ab90.html

Attached:

A brief discussion on the method of inserting records with self-increasing primary key in master and child table INT

Http://www.knowsky.com/301344.html

[@ more@]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report