Re: How to retrieve the generated serial id from a batch of inserts
Posted in 2006
Topics: Connectivity: ODBC / JDBC / .NET, Server Administration, Java & JDBC Development, Versions, Editions & End-of-Life
There is easier and faster was to retrieve generated key. You can use com.informix.jdbc.IfmxStatement::getSerial() or com.informix.jdbc.IfmxStatement::getSerial8() methods to do same. You can also used the java.sql.Connection::prepareStatement(String sql, int autoGeneratedKeys) method along with java.sql.Statement::getGeneratedKeys() method. These are JDBC standard methods. However these standard methods available only with JDBC300JC1 and later. You will also need JDK1.4 and IDS 9.50XC1 or later to be able to use these standard methods. As far as using these in conjunction with batch inserts is concerned , I doubt if any of these methods work. Amit --- Gabriel Belingueres <gaby@ieee.org> wrote: > Hi, > > >From Java (using JDBC) I can execute an INSERT > statement on a table > which its PK is of a SERIAL datatype, and to > retrieve the just > generated pk, I execute the following select: > > select dbinfo('sqlca.sqlerrd1') from systables where > tabid=1 > > This works OK. > > Now I want to make several INSERTs into that table, > and I want to use > batch processing for that, using addBatch() and > executeBatch on a > PreparedStatement. > > However, the previous query does not return a > ResultSet with the > generated PKs, but with only one of them (the last > generated SERIAL, > but not the others). > > Is it any way to solve this? > > Regards, > Gabriel > > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list >
Hi Amit. I've tried the getGeneratedKeys() method but I received an SQLException telling that it is not supported. I'm using JDBC driver 3.0 JC3, so probably it is because I'm connected to an IDS 9.2 engine. :-( I did give up with batch inserts and falled back to make the INSERTs individually and recovering the PK with getSerial(). Thanks, Gabriel Amit Dandekar ha escrito: > There is easier and faster was to retrieve generated > key. > You can use > com.informix.jdbc.IfmxStatement::getSerial() or > com.informix.jdbc.IfmxStatement::getSerial8() methods > to do same. > > > > You can also used the > java.sql.Connection::prepareStatement(String sql, int > autoGeneratedKeys) method along with > java.sql.Statement::getGeneratedKeys() method. > These are JDBC standard methods. > However these standard methods available only with > JDBC300JC1 and later. You will also need JDK1.4 and > IDS 9.50XC1 or later to be able to use these standard > methods. > > > > As far as using these in conjunction with batch > inserts is concerned , I doubt if any of these methods > work. > > > > Amit > > > > --- Gabriel Belingueres <gaby@ieee.org> wrote: > > > Hi, > > > > >From Java (using JDBC) I can execute an INSERT > > statement on a table > > which its PK is of a SERIAL datatype, and to > > retrieve the just > > generated pk, I execute the following select: > > > > select dbinfo('sqlca.sqlerrd1') from systables where > > tabid=1 > > > > This works OK. > > > > Now I want to make several INSERTs into that table, > > and I want to use > > batch processing for that, using addBatch() and > > executeBatch on a > > PreparedStatement. > > > > However, the previous query does not return a > > ResultSet with the > > generated PKs, but with only one of them (the last > > generated SERIAL, > > but not the others). > > > > Is it any way to solve this? > > > > Regards, > > Gabriel > > > > _______________________________________________ > > Informix-list mailing list > > Informix-list@iiug.org > > http://www.iiug.org/mailman/listinfo/informix-list > >