You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Barnett, Brian W." <bb...@scholarinc.com> on 2005/01/27 18:50:01 UTC
RE: Another ODBC OT Question
What rdbms are you using?
-----Original Message-----
From: Brandon Mercer [mailto:brandon@eutonian.com]
Sent: Thursday, January 27, 2005 10:56 AM
To: Struts Users Mailing List
Subject: Another ODBC OT Question
Hello,
Ok, I've got another off topic question :-P. That's two in a day!
Three strikes and I'm out. lol Anyhow, I am inserting information into
a database and I need to get the auto_increment value from my first
insert and use the value it returns to create an entry in another
table. Does anyone have a code snippet that they could show me? Thanks,
Brandon
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: Another ODBC OT Question
Posted by Erik Weber <er...@mindspring.com>.
Thanks for the post. I didn't realize MySQL had implemented so much of
JDBC 3. A standard API for retrieval of RDBMS-generated keys rocks! This
on top of the recent improvements in driver performance. Awesome.
Erik
Brandon Mercer wrote:
> Erik Weber wrote:
>
>> Sorry for all those local disk links and other junk. Cut and paste.
>>
> Thanks everyone this article
> http://dev.mysql.com/tech-resources/articles/autoincrement-with-connectorj.html
> was the ticket for me. We all know how it gets when you're writing
> code all day long and you start to forget how to function! :-P
> Thanks for the patience and help. I've got working now. Regards,
> Brandon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Another ODBC OT Question
Posted by Brandon Mercer <br...@eutonian.com>.
Erik Weber wrote:
> Sorry for all those local disk links and other junk. Cut and paste.
>
Thanks everyone this article
http://dev.mysql.com/tech-resources/articles/autoincrement-with-connectorj.html
was the ticket for me. We all know how it gets when you're writing code
all day long and you start to forget how to function! :-P Thanks for
the patience and help. I've got working now.
Regards,
Brandon
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Another ODBC OT Question
Posted by Erik Weber <er...@mindspring.com>.
Sorry for all those local disk links and other junk. Cut and paste.
Erik
Erik Weber wrote:
>
>
> <mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.2&filename=Getting_unique_ID>
>
>
>
> You use MySQL's AUTO_INCREMENT function (then omit the value
> during an insert and MySQL will insert it for you) and related
> syntax, which is all covered in the manual:
>
>
>
> 21.2.12.3 How to Get the Unique ID for the Last Inserted Row
>
> <mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.2&filename=Getting_unique_ID>
>
>
> If you insert a record into a table that contains an |AUTO_INCREMENT|
> column, you can obtain the value stored into that column by calling
> the |mysql_insert_id()| function.
>
> You can check whether a value was stored into an |AUTO_INCREMENT|
> column by executing the following code. This also checks whether the
> query was an |INSERT| with an |AUTO_INCREMENT| index:
>
> if (mysql_error(&mysql)[0] == 0 &&
> mysql_num_fields(result) == 0 &&
> mysql_insert_id(&mysql) != 0)
> {
> used_id = mysql_insert_id(&mysql);
> }
>
> For more information, see section 21.2.3.32 |mysql_insert_id()|
> <mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.3&filename=manual_Clients.html>.
>
>
> When a new |AUTO_INCREMENT| value has been generated, you can also
> obtain it by executing a |SELECT LAST_INSERT_ID()| statement
> |mysql_query()| and retrieving the value from the result set returned
> by the statement.
>
>
> That's straight out of the MySQL 5.0 manual. . .
>
> Erik
>
>
> Brandon Mercer wrote:
>
>> Barnett, Brian W. wrote:
>>
>>> What rdbms are you using?
>>>
>>>
>> Sorry, that would have been helpful huh! lol MySQL Connector/J
>> (obviously) 3.0.x. I think I know how to get the last id... but do I
>> create another insert the same way I did the first?
>> Thanks,
>> Brandon
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Another ODBC OT Question
Posted by Erik Weber <er...@mindspring.com>.
<mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.2&filename=Getting_unique_ID>
You use MySQL's AUTO_INCREMENT function (then omit the value
during an insert and MySQL will insert it for you) and related
syntax, which is all covered in the manual:
21.2.12.3 How to Get the Unique ID for the Last Inserted Row
<mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.2&filename=Getting_unique_ID>
If you insert a record into a table that contains an |AUTO_INCREMENT|
column, you can obtain the value stored into that column by calling the
|mysql_insert_id()| function.
You can check whether a value was stored into an |AUTO_INCREMENT| column
by executing the following code. This also checks whether the query was
an |INSERT| with an |AUTO_INCREMENT| index:
if (mysql_error(&mysql)[0] == 0 &&
mysql_num_fields(result) == 0 &&
mysql_insert_id(&mysql) != 0)
{
used_id = mysql_insert_id(&mysql);
}
For more information, see section 21.2.3.32 |mysql_insert_id()|
<mailbox:///home/eweber/.mozilla/eweber/dtplse79.slt/Mail/mail.mindspring.com/Drafts?number=3515320&part=1.3&filename=manual_Clients.html>.
When a new |AUTO_INCREMENT| value has been generated, you can also
obtain it by executing a |SELECT LAST_INSERT_ID()| statement
|mysql_query()| and retrieving the value from the result set returned by
the statement.
That's straight out of the MySQL 5.0 manual. . .
Erik
Brandon Mercer wrote:
> Barnett, Brian W. wrote:
>
>> What rdbms are you using?
>>
>>
> Sorry, that would have been helpful huh! lol MySQL Connector/J
> (obviously) 3.0.x. I think I know how to get the last id... but do I
> create another insert the same way I did the first?
> Thanks,
> Brandon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: Another ODBC OT Question
Posted by DG...@EvergreenInvestments.com.
I googled this:
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLD,GGLD:2004-11,GGLD:en&q=jdbc+mysql+auto%5Fincrement
and found this:
http://dev.mysql.com/tech-resources/articles/autoincrement-with-connectorj.html
It was too easy, so it's probably the wrong thing.
Brandon Mercer <br...@eutonian.com>
01/27/2005 01:17 PM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
Struts Users Mailing List <us...@struts.apache.org>
cc
Subject
Re: Another ODBC OT Question
Barnett, Brian W. wrote:
>What rdbms are you using?
>
>
Sorry, that would have been helpful huh! lol MySQL Connector/J
(obviously) 3.0.x. I think I know how to get the last id... but do I
create another insert the same way I did the first?
Thanks,
Brandon
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Another ODBC OT Question
Posted by Brandon Mercer <br...@eutonian.com>.
Barnett, Brian W. wrote:
>What rdbms are you using?
>
>
Sorry, that would have been helpful huh! lol MySQL Connector/J
(obviously) 3.0.x. I think I know how to get the last id... but do I
create another insert the same way I did the first?
Thanks,
Brandon
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org