If you have a JDBC 3.0 compliant driver, this is what you can do in a portable
way, using the getGeneratedKeys method of the Statement interface:
Statement stmt = conn.createStatement();
// indicate that the key generated is going to be returned
int rows = stmt.executeUpdate("INSERT INTO ORDERS " +
"(ISBN, CUSTOMERID) " +
"VALUES (195123018, �BILLG�)",
Statement.RETURN_GENERATE_KEYS);
ResultSet rs = stmt.getGeneratedKeys();
boolean b = rs.next();
if (b == true) {
// retrieve the new key value
...
}
URL:
http://java.sun.com/products/jdbc
Kevin Gaasch wrote:
> I would like to see everyone's suggestions on how to handle Automatically
> generated primary keys. Utility objects, vendor specific, etc...
>
> --------------------------------------------------
> Kevin E. Gaasch
> Anderson Merchandisers, Inc.
> Java Application Development
> Lotus Notes Development
> [EMAIL PROTECTED]
> (806)376-6251 ext. 4819
> (800)999-0904 ext. 4819
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
--
Bruno Antunes,
Java Software Engineer
email: mailto:[EMAIL PROTECTED]
Phone: +351.21.7994200
Fax : +351.21.7994242
WhatEverSoft - Java Center
Centro de Competencia Java
Praca de Alvalade, 6 - Piso 4
1700-036 Lisboa - Portugal
URL: http://www.whatevernet.com
********************* INTERNET MAIL FOOTER *************************
A presente mensagem pode conter informacao considerada confidencial.
Se o receptor desta mensagem nao for o destinatario indicado, fica
expressamente proibido de copiar ou enderecar a mensagem a
terceiros. Em tal situacao, o receptor devera destruir a presente
mensagem e por gentileza informar o emissor de tal facto.
--------------------------------------------------------------------
Privileged or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message, you
may not copy or deliver this message to anyone. In such case, you
should destroy this message and kindly notify the sender by reply
email.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".