commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From george stewart <gstew...@us-south.net>
Subject Re: [dbutils] more results
Date Wed, 05 Mar 2003 19:07:36 GMT
"Juozas Baliuka" <baliuka@centras.lt> writes:

> > getMoreResults() precedes getResultSet().
> >
> > Using this is slightly more efficient than an update followed by a query.
> JDBC documentation says I must to call getMoreResults() after
> getResultSet().
> I have no way to test this stuff, doe's some opensource RDMS driver supports
> getResultSet() after update and
>  something like this ?
> INSERT  INTO tbl (id) VALUES (
>   (
>          CASE WHEN ( SELECT  MAX(id)  FROM tbl )  is NULL
>                       THEN 0
>                       ELSE  (SELECT  MAX(id)  FROM tbl )
>           END
>  )  + 1
> ) ;
> SELECT  MAX(id) FROM tbl;
> 

I'll try MySQL.  It has support for identity.  So you should be able to use:

Insert into (...)
Values(...)
SELECT LAST_INSERT_ID()

Snippet below is in the FAQ for inet's MS SQL Server driver.

http://www.inetsoftware.de/English/produkte/JDBC_Overview/default.htm
>>>>>>>>>>>>>>>>>>>>>

How do I retrieve the value from the identitiy column of a newly inserted record

The best solution for the JDBC≥ 1.22 driver i-net UNA≥ 2000 is to call two statements
in one.
For example:

    st.execute( "Insert into YourTable(..) Values(..) SELECT @@IDENTITY" );
  if (st.getUpdateCount() == 1) {
      st.getMoreResults();
      rs = st.getResultSet();
      rs.next();
      Object identity = rs.getObject();
  }

<<<<<<<<<<<<<<<<<


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message