You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Carole E. Mah" <ca...@mama.stg.brown.edu> on 2002/05/01 18:56:34 UTC

JSTL: sql

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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Carole E. Mah                     carolem@stg.brown.edu
           Senior Programmer/Analyst
   Brown University Scholarly Technology Group
               phn 401-863-2669
               fax 401-863-9313
            http://www.stg.brown.edu/
  personal: http://www.stg.brown.edu/~carolem/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by peter lin <pe...@labs.gte.com>.
this might not be the answer you're looking for, but in high end
databases, the recommended method of doing incremental unique ID is to
use a stored procedure which gets the next id and uses it in an insert
statement. The stored procedure then passes the unique id back.

autoincrement is typically used in low and medium level databases.
Managing ID in RDBMS is a large part of what DBA's handle.  The reason
high end databases do this is because the data model is typically
complex where a simple transaction requires updates and inserts in
multiple tables.

Your other option is to get the last ID and increment it in a bean or
jsp.  Of course this means changing the property of the ID column in
your table.

peter lin



"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
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> Carole E. Mah                     carolem@stg.brown.edu
>            Senior Programmer/Analyst
>    Brown University Scholarly Technology Group
>                phn 401-863-2669
>                fax 401-863-9313
>             http://www.stg.brown.edu/
>   personal: http://www.stg.brown.edu/~carolem/
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Paul DuBois <pa...@snake.net>.
>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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by peter lin <pe...@labs.gte.com>.
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.

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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL: sql

Posted by Paul DuBois <pa...@snake.net>.
At 13:59 -0400 5/1/02, Baron, Elizabeth wrote:
>Is this valid on Oracle as well, or just mysql?  If not, is there any
>"universal" way to do it?
>
>Thanks,
>Elizabeth Baron

LAST_INSERT_ID() is MySQL-specific, just like AUTO_INCREMENT columns.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL: sql

Posted by Henri Yandell <ba...@generationjava.com>.

On Wed, 1 May 2002, Baron, Elizabeth wrote:

> Is this valid on Oracle as well, or just mysql?  If not, is there any
> "universal" way to do it?

Not until JDBC 3.0 becomes standard. Or by doing it completely in Java as
others have suggested.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: JSTL: sql

Posted by "Baron, Elizabeth" <EB...@tiaa-cref.org>.
Is this valid on Oracle as well, or just mysql?  If not, is there any
"universal" way to do it?

Thanks,
Elizabeth Baron

-----Original Message-----
From: Martin Cooper [mailto:martin.cooper@tumbleweed.com] 
Sent: Wednesday, May 01, 2002 1:47 PM
To: Tag Libraries Users List
Subject: Re: JSTL: sql


As long as you do the SELECT LAST_INSERT_ID() in the same transaction as
the
INSERT itself, there's no issue. The value of the most recently
generated id
is maintained per connection, and using a transaction guarantees that
you'll
be using the same connection.

--
Martin Cooper


----- Original Message -----
From: "Morris Hirsch" <mo...@mama.stg.brown.edu>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Wednesday, May 01, 2002 10:35 AM
Subject: Re: JSTL: sql


> The problem is not about your own thread doing several related
updates,
> but some other thread doing an INSERT just after you do,
> and before you get a chance to SELECT LAST_INSERT_ID()
>
> If there is any chance of it (anything except a single user can do it)
> you must ensure thread safety with either single-thread attribute,
> or synchronize (this) on the block.
>
> On Wed, 1 May 2002, 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:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


**********************************************************************
This message, including any attachments, contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, please contact sender immediately by reply e-mail and destroy all copies.  You are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.
TIAA-CREF
**********************************************************************

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Martin Cooper <ma...@tumbleweed.com>.
As long as you do the SELECT LAST_INSERT_ID() in the same transaction as the
INSERT itself, there's no issue. The value of the most recently generated id
is maintained per connection, and using a transaction guarantees that you'll
be using the same connection.

--
Martin Cooper


----- Original Message -----
From: "Morris Hirsch" <mo...@mama.stg.brown.edu>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Wednesday, May 01, 2002 10:35 AM
Subject: Re: JSTL: sql


> The problem is not about your own thread doing several related updates,
> but some other thread doing an INSERT just after you do,
> and before you get a chance to SELECT LAST_INSERT_ID()
>
> If there is any chance of it (anything except a single user can do it)
> you must ensure thread safety with either single-thread attribute,
> or synchronize (this) on the block.
>
> On Wed, 1 May 2002, 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:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Paul DuBois <pa...@snake.net>.
At 13:35 -0400 5/1/02, Morris Hirsch wrote:
>The problem is not about your own thread doing several related updates,
>but some other thread doing an INSERT just after you do,
>and before you get a chance to SELECT LAST_INSERT_ID()
>
>If there is any chance of it (anything except a single user can do it)
>you must ensure thread safety with either single-thread attribute,
>or synchronize (this) on the block.

I'll repeat my response to Peter's message:


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.


>
>On Wed, 1 May 2002, 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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Morris Hirsch <mo...@mama.stg.brown.edu>.
The problem is not about your own thread doing several related updates,
but some other thread doing an INSERT just after you do,
and before you get a chance to SELECT LAST_INSERT_ID()

If there is any chance of it (anything except a single user can do it)
you must ensure thread safety with either single-thread attribute,
or synchronize (this) on the block.

On Wed, 1 May 2002, 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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Paul DuBois <pa...@snake.net>.
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 1 May 2002, Hans Bergsten wrote:

> Another alternative is to develop your own class for generating unique
> IDs:
> 
>    public class IDGenerator {
>      public long getNextId() {
>        // Some algorithm, possibly based on a timestamp and a sequence
>        // number, to generate the next id
>        return nextId;
>      }
>    }

Yeah, I tend to like this approach too.  Java offers java.rmi.server.UID,
too, if you want to use a more "standard" mechanism.

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming this summer from Manning Publications)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Henri Yandell wrote:
> Very very unlikely. I don't think any drivers provide this yet. The JDBC
> 3.0 spec does have such a thing, but it's new and not really common.
> 
> Two Options:
> 
> 1) Find some SQL that is mysql specific to find it out. I know there is
> something, I'm just not sure what. I'll try to hunt it out.
> 
> 2) Look at the mysql driver for some extra methods to do such a thing. I
> know Oracle's driver has a bunch of extra things in, but I'm not sure if
> Mysql does. I've never tried looking at the source to find extra non-spec
> code.

Another alternative is to develop your own class for generating unique
IDs:

   public class IDGenerator {
     public long getNextId() {
       // Some algorithm, possibly based on a timestamp and a sequence
       // number, to generate the next id
       return nextId;
     }
   }

   <jsp:useBean id="idGenerator" class="..." scope="application" />
   <c:set var="nextId" value="${ideGenerator.nextId}" />
   <sql:setDataSource
     url="${db_server}"
     user="${db_login}"
     password="{db_password}"
   />
   <sql:query>
     INSERT INTO foo (id, name, phone) VALUES (?, 'Jane Doe','555-1212')
     <sql:param value="${nextId}" />
   </sql:query>

   The id I used was: <c:out value="${nextId}" />

Automatic id generation is one area that makes it hard to move between
databases, so rolling your own makes the application more portable.

For ideas about how to generate unique IDs, see a database book,
for instance "Database Programming with JDBC and Java" by George
Reese (O'Reilly).

Hans

> On Wed, 1 May 2002, 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
>>- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>>Carole E. Mah                     carolem@stg.brown.edu
>>           Senior Programmer/Analyst
>>   Brown University Scholarly Technology Group
>>               phn 401-863-2669
>>               fax 401-863-9313
>>            http://www.stg.brown.edu/
>>  personal: http://www.stg.brown.edu/~carolem/
>>
>>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com
JavaServer Pages	http://TheJSPBook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Shawn Bayern <ba...@essentially.net>.
Right - there isn't a portable way of doing this with JDBC.  You can use a
database-specific feature to acquire the info, but note that you'll need
to do this inside a <sql:transaction> tag, since the "last OID"-type
features are always connection-specific, and <sql:transaction> is
currently the only way of ensuring that two successive database operations
use the same connection.

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming this summer from Manning Publications)

On Wed, 1 May 2002, Henri Yandell wrote:

> Very very unlikely. I don't think any drivers provide this yet. The JDBC
> 3.0 spec does have such a thing, but it's new and not really common.
> 
> Two Options:
> 
> 1) Find some SQL that is mysql specific to find it out. I know there is
> something, I'm just not sure what. I'll try to hunt it out.
> 
> 2) Look at the mysql driver for some extra methods to do such a thing. I
> know Oracle's driver has a bunch of extra things in, but I'm not sure if
> Mysql does. I've never tried looking at the source to find extra non-spec
> code.
> 
> Hen
> 
> On Wed, 1 May 2002, 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
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > Carole E. Mah                     carolem@stg.brown.edu
> >            Senior Programmer/Analyst
> >    Brown University Scholarly Technology Group
> >                phn 401-863-2669
> >                fax 401-863-9313
> >             http://www.stg.brown.edu/
> >   personal: http://www.stg.brown.edu/~carolem/
> >
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: JSTL: sql

Posted by Henri Yandell <ba...@generationjava.com>.
Very very unlikely. I don't think any drivers provide this yet. The JDBC
3.0 spec does have such a thing, but it's new and not really common.

Two Options:

1) Find some SQL that is mysql specific to find it out. I know there is
something, I'm just not sure what. I'll try to hunt it out.

2) Look at the mysql driver for some extra methods to do such a thing. I
know Oracle's driver has a bunch of extra things in, but I'm not sure if
Mysql does. I've never tried looking at the source to find extra non-spec
code.

Hen

On Wed, 1 May 2002, 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
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> Carole E. Mah                     carolem@stg.brown.edu
>            Senior Programmer/Analyst
>    Brown University Scholarly Technology Group
>                phn 401-863-2669
>                fax 401-863-9313
>             http://www.stg.brown.edu/
>   personal: http://www.stg.brown.edu/~carolem/
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>