>the only downside of that approach is if another process performs an
>insert in between the time the insert is finished and select
>last_insert_id() is issued.

Not true.  LAST_INSERT_ID() guarantees that you get the AUTO_INCREMENT
value generated on your own connection, regardless of what any other
clients are doing.

This assumes that you use <sql:transaction> (as per Shawn's message),
to make sure that the query that generates the AUTO_INCREMENT value
and the query that selects it are issued using the same connection.

>
>peter lin
>
>
>Paul DuBois wrote:
>>
>>  At 12:56 -0400 5/1/02, Carole E. Mah wrote:
>>  >Does anyone know if the JSTL database tags (<sql>) provide any method for
>>  >retrieving the unique ID of the row that was inserted last (when you set
>>  >up you mySQL database table to AUTO_INCREMENT the unique id).
>>  >
>>  >This is how I do it using PHP, which provides the mysql_insert_id()
>>  >function for just this purpose:
>>  >
>>  >   $query = "INSERT INTO foo (name, phone) VALUES ('Jane Doe','555-1212')";
>>  >   $LINK = mysql_pconnect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD);
>>  >   $result = mysql_db_query ("$DB", $query);
>>  >   $my_id = mysql_insert_id($LINK);
>>  >
>>  >Thanks!
>>  >
>>  >-carole
>>
>>  Don't know of any such thing in JSTL, but you can issue this query
>>  to get the value from the server:
>>
>  > SELECT LAST_INSERT_ID()


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to