"Juozas Baliuka" <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to