tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Layman <randy.lay...@aswethink.com>
Subject RE: mm.mysql - getLastInsertID() question
Date Wed, 28 Feb 2001 21:21:35 GMT

	Never worked with this, but the directions seem to indicate:


org.gjt.mm.mysql.Statement stmt =
(org.gjt.mm.mysql.Statement)dbConnection.createStatement();

int count = stmt.executeUpdate("INSERT INTO ...");

// here i need to catch the ID that was just created 
// in the auto_increment field..
id = stmt.getLastIncrementId()

	I don't know the type this method returns, but its probably not to
hard to find out.

	Randy

-----Original Message-----
From: Cato, Christopher [mailto:ccato@rational.com]
Sent: Wednesday, February 28, 2001 4:55 PM
To: tomcat-user@jakarta.apache.org
Subject: OT: mm.mysql - getLastInsertID() question


Hello. I'm wondering if anyone here would like to elighten me on
how to use the getLastInsertId() function in the mm.mysql jdbc
driver??

I know it's an offtopic question but if you can help, please do so.

I need to retrieve the auto_increment id of the last row created in 
a table. Since there may be concurrent writes to the same table, I
cannot do a "select max(id)" to get it. I need to use the method
in mm.mysql. Only problem is, I just don't know how to use it.

Quoting m.matthews (mm.mysql authour):
--------------------------------------
With my driver, MM.MySQL available at 
http://www.worldserver.com/mm.mysql/ you can call get the id`s of 
AUTO_INCREMENT inserts by casting your 
java.sql.Statement/PreparedStatement to 
org.gjt.mm.mysql.Statement/PreparedStatement and calling 
getLastInsertID() on it.
--------------------------------------




Now, how do I use this from the following code snippet?

my code:
--------------------------------------
public void createSite(String a, String b, String c)
{
try{

// guess I need to cast this some other way, but how?
Statement stmt = dbConnection.createStatement();

int count = stmt.executeUpdate("INSERT INTO ...");

// here i need to catch the ID that was just created 
// in the auto_increment field..
}
catch (SQLException e)
{
log(e.getMessage());
}
}


Regards,
Christopher Cato

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, email: tomcat-user-help@jakarta.apache.org

Mime
View raw message