Languages :: Java :: how to retrieve autoincrement value insert mysql jsp |
|||
| By: Nono |
Date: 14/06/2007 14:09:39 |
Points: 20 | Status: Answered Quality : Excellent |
| how to retrieve in jsp the autoincrement value of the last insert in mysql ? | |||
| By: VGR | Date: 14/06/2007 14:50:06 | Type : Answer |
|
| the official answer is to use mysql_last_insert_id(), but other solutions do exist : - query "id" (or your PRI KEY/AUTOINC column name) from the same table with ORDER BY id DESC LIMIT 1; // not 100% reliable, but usually is - query "id" from the same table with discriminant values that return the same row as the one that was inserted // 100% reliable - query "show table status" , retrieve your column name and get the "Auto_increment" column... (this is the next value as the one inserted IMHO) // no more reliable as the first solution, but no more unreliable either - human imagination is infinite... |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








