Bonjour
comment faire pour retourner id(automatique) d'une table (base mysql) lors de l'insertion,
et merci
Version imprimable
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:
:arrow: http://dev.mysql.com/tech-resources/...onnectorj.htmlCode:
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 }
;)