List:MySQL and Java« Previous MessageNext Message »
From:Steve Forsyth Date:July 16 2002 6:20pm
Subject:Re: returning identity field from a select statement
View as plain text  
Are there any JDBC 3.0 drivers for MySql?


>From: Andrew Houghton <aah@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.
>
>>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.




_________________________________________________________________
http://www.hotmail.com

Thread
returning identity field from a select statementMHall16 Jul
  • Re: returning identity field from a select statementJeff Kilbride16 Jul
    • RE: returning identity field from a select statementJon Frisby19 Jul
      • Re: returning identity field from a select statementMark Matthews19 Jul
        • RE: returning identity field from a select statementJon Frisby19 Jul
  • Re: returning identity field from a select statementTim Endres16 Jul
  • Re: returning identity field from a select statementJavier BolaƱos Molina(MCIC)16 Jul
    • Re: returning identity field from a select statementAndrew Houghton16 Jul
Re: returning identity field from a select statementMark Matthews16 Jul
Re: returning identity field from a select statementSteve Forsyth16 Jul
Re: returning identity field from a select statementSteve Forsyth16 Jul
  • Re: returning identity field from a select statementMark Matthews16 Jul