List:MySQL and Java« Previous MessageNext Message »
From:Tim Endres Date:May 24 1999 3:27pm
Subject:Re: Get AUTO INCREMENT VALUE after an INSERT in a SERVLET
View as plain text  
On Mon, May 24 1999, Ivo Pescia wrote:
> hello,
> 
> how can i retrieve the last AUTO INCREMENT Value
> after having performed an INSERT Query.
> 
> I am using JAVA Servlets    tw1.JDBC Driver AND MYSQL.

// INSERT

			queryStr =
				"INSERT INTO description " +
				"  ( synopsis ) VALUES ( '' ) ";

			Statement stmt = this.handler.createStatement();
			rows = stmt.executeUpdate( queryStr );
			stmt.close();

// GET ID
int ID;

						String queryStr = "select LAST_INSERT_ID()";
			Statement stmt = this.handler.createStatement();
			ResultSet rs = stmt.executeQuery( queryStr );
			if ( rs.next() )
				{
				ID = rs.getInt(1);
				}
			rs.close();
			stmt.close();


tim.
Tim Endres, ICE Engineering, Inc.
   mailto: time@stripped    http://www.ice.com
   "Usenet - A slow moving self parody." -- Peter Honeyman
Thread
Get AUTO INCREMENT VALUE after an INSERT in a SERVLETIvo Pescia24 May
  • Re: Get AUTO INCREMENT VALUE after an INSERT in a SERVLETTim Endres24 May