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                     [EMAIL PROTECTED]
>>           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:   <mailto:[EMAIL PROTECTED]>
>>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>>
>>
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
> 


-- 
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
JavaServer Pages        http://TheJSPBook.com


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

Reply via email to