-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Steve Forsyth wrote:
| Are there any JDBC 3.0 drivers for MySql?
|
|
|> From: Andrew Houghton <aah@stripped>
|> To: "Javier Bolaños Molina(MCIC)" <javier@stripped>
|> CC: MHall@stripped, java@stripped
|> Subject: Re: returning identity field from a select statement
|> Date: Tue, 16 Jul 2002 09:23:36 -0700
|>
|> Not to mention that JDBC3.0 / JDK 1.4 has a getGeneratedKeys() method
|> which will do exactly what you want. Works fine for Statements at the
|> moment, but seems not to work for PreparedStatements.
|>
|> - a.
|>
|> Javier Bolaños Molina(MCIC) wrote:
|>
|>> I don't know a function that does this but if you take this steps you
|>> will
|>> have the same result
|>>
|>>
|>> PreparedStatement stmtInsertSomething =
|>> conn.prepareStatement("INSERT INTO sometable (autoincrement_id,
|>> other_field) VALUES ('', ?);
|>>
|>> stmtInsertSomething.setInt(1, somevalue);
|>>
|>> stmtInsertSomething.executeUpdate();
|>> PreparedStatement stmtGetLastID = conn.prepareStatement("SELECT
|>> LAST_INSERT_ID()");
|>>
|>> ResultSet rs = stmtGetLastID.executeQuery();
|>> rs.next();
|>> int lastID = rs.getInt(1);
|>>
|>>
|>> that's all.
|>>
|>> Good luck!
|>>
|>>
|>>
|>> On Tue, 16 Jul 2002 MHall@stripped wrote:
|>>
|>>
|>>> MYSQL already has a function mysql_insert_id() for use in the C API but
|>>> this does not work in java.
|>>>
|>>> Is there an equivalent function that I can use in my Java servlet to
|>>> return
|>>> the identity field after an insert ?
|>>>
|>>> I am using the version 1.4 JDK and the version 2.0.14 MM.MYSQL JDBC
|>>> Driver
|>>> for mySQL .
|>>>
|>>> I am using version 3.23.36 of mySQL.
|>>>
|>>> Can anyone help ?
|>>>
|>>>
|>>>
|>>> Michael Hall
|>>> Email: MHall@stripped
|>>>
|>>>
|>>>
|>>> ---------------------------------------------------------------------
|>>> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html"
|>>> before
|>>> posting. To request this thread, e-mail java-thread4005@stripped
|>>>
|>>> To unsubscribe, send a message to the address shown in the
|>>> List-Unsubscribe header of this message. If you cannot see it,
|>>> e-mail java-unsubscribe@stripped instead.
|>>>
|>>>
|>>
|>>
|>>
|>> ---------------------------------------------------------------------
|>> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html"
|>> before
|>> posting. To request this thread, e-mail java-thread4011@stripped
|>>
|>> To unsubscribe, send a message to the address shown in the
|>> List-Unsubscribe header of this message. If you cannot see it,
|>> e-mail java-unsubscribe@stripped instead.
|>>
|>>
|>>
|>
|>
|> --
|> Andrew Houghton
|> aah@stripped
|>
|>
|> ---------------------------------------------------------------------
|> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
|> posting. To request this thread, e-mail java-thread4012@stripped
|>
|> To unsubscribe, send a message to the address shown in the
|> List-Unsubscribe header of this message. If you cannot see it,
|> e-mail java-unsubscribe@stripped instead.
|
|
|
|
|
| _________________________________________________________________
| Join the worlds largest e-mail service with MSN Hotmail.
| http://www.hotmail.com
|
|
| ---------------------------------------------------------------------
| Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
| posting. To request this thread, e-mail java-thread4013@stripped
|
| To unsubscribe, send a message to the address shown in the
| List-Unsubscribe header of this message. If you cannot see it,
| e-mail java-unsubscribe@stripped instead.
|
Yes and no. Statment.getGeneratedKeys() works in MM.MySQL-2.0.14 (but
not for PreparedStatements...it's a three-line patch to get it to work,
though).
MM.MySQL-2.0.15 (soon to be released after some testing), has at least
all JDBC-3.0 methods stubbed out, and getGeneratedKeys() works for all
types of Statements.
-Mark
- --
For technical support contracts, visit https://order.mysql.com/?ref=mmma
~ __ ___ ___ ____ __
~ / |/ /_ __/ __/ __ \/ / Mark Matthews <mark@stripped>
~ / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java
~ /_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA
~ <___/ www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6-2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE9NHNstvXNTca6JD8RApUpAJ9v2L7l8vzVOsL7OGcockqkLqBG7QCfTsa7
oCeaSCklTyxVWpjKxMRJs94=
=08bI
-----END PGP SIGNATURE-----