Bonjour
comment faire pour retourner id(automatique) d'une table (base mysql) lors de l'insertion,
et merci
Bonjour
comment faire pour retourner id(automatique) d'une table (base mysql) lors de l'insertion,
et merci
Il y a plusieurs manières... La plus propre est:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 stmt.executeUpdate("INSERT INTO foo VALUES (NULL, '...')", Statement.RETURN_GENERATED_KEYS); int autoIncKeyFromApi = -1; rs = stmt.getGeneratedKeys(); if (rs.next()) { autoIncKeyFromApi = rs.getInt(1); } else { // pas de chance, id non dispo }http://dev.mysql.com/tech-resources/...onnectorj.html
![]()
Partager