5 messages in com.mysql.lists.javaApparent bug retrieving Last Insert I...
FromSent OnAttachments
Alec...@Quantel.Com09 Aug 2002 10:15 
Mark Matthews10 Aug 2002 12:29 
Mark Matthews13 Aug 2002 04:20 
Edwin van Nuil16 Aug 2002 05:08 
Mark Matthews16 Aug 2002 06:15 
Subject:Apparent bug retrieving Last Insert ID using mm.mysql
From:Alec...@Quantel.Com (Alec@Quantel.Com)
Date:08/09/2002 10:15:58 AM
List:com.mysql.lists.java

This bug is found using Java and the MM.MySQL driver, but I do not think it is actually caused by the JDBC driver but rather comes from the MySQL daemon. However, I am sending to both lists in case it is a driver problem.

The Last Insert ID can, of course, be retrieved by executing the query SELECT LAST_INSERT_ID(). However, MM.MySQL also offers the shortcut Statement.getLastInsertID(), which I prefer to use believing it to be quicker. This normally works. However, it seems to fail after executing a command of the form INSERT INTO table VALUES (...), (...), ..., (...) After executing this command, getLastInsertID() returns a value of 0, whereas SELECT LAST INSERT_ID returns the correct value.

I attach a Java test program which demonstrates the fault. It should be compiled then run using java AITest <hostname - often 127.0.0.1> <databasename - usually test> <username> {<password>}

(See attached file: AITest.java)

OS: Windows 2000 MySQL: 4.0.2-alpha-max-nt, binary download MM.MySQL: 1-14 Java: j2sdk 1.4.0_01

Alec Cawley

mysql, query