> On 19 Oct 2001 08:34:47 -0200, Marcus Brito wrote: > > >> As an alternative to fetching the parameters from the original definition > >> as above, you can use > >> SELECT last_value FROM seqname; > >> to obtain the last value allocated by any backend. > > > >You can't trust this. Perhaps some other process (other bean, other > >application, other thread) has alredy modified the sequence.
yes you can. thats the whole idea. sequences will have a cache, when you first query a sequence in a connection, you will be given the first of the cache. the cache will be per-connection, and you wont have to worry about other processes. as far as portability is concerned, if you're happy to limit yourself to dbs with sequences, you can easily have a config switch, or even have the sql in the config itself... there are plenty of options. cheers dim > > > >Suppose you have a table named MYTABLE, with a column named TBL_ID, > >whose value is obtained from the SEQ_TBL_ID sequence. > > > >If you do something like: > > > >PreparedStatement stmt =3D dbConn.prepareStatement("INSERT INTO mytable(tbl= > >_id) VALUES (nextval('seq_tbl_id'))"); > >stmt.executeUpdate(); > > > >you should do the following (in JBoss) to get the value just inserted > > > >int oid =3D ((org.postgresql.Statement)(((org.jboss.pool.jdbc.PreparedState= > >mentInPool)stmt).getUnderlyingPreparedStatement())).getInsertedOID(); > > > >and then > > > >stmt =3D dbConn.prepareStatement("SELECT tbl_id FROM mytable WHERE oid =3D = > >?"); > >stmt.setInt(1, oid); > >ResultSet rs =3D stmt.executeQuery(); > >rs.next(); > >int tbl_id =3D rs.getInt("tbl_id"); > > > >This is pretty ugly, specilly the line to obtain the inserted OID. So > >many typecasts. Also, this is not portable across application servers. > >But is the only way to make sure you obtain the last value you inserted. > >If I'm wrong, please someone correct me. > > > >--=20 > >Ja ne, > > Pazu > > mailto: [EMAIL PROTECTED] > > > >Anime Gaiden: de f=E3s para f=E3s, sempre. > > -------------------------------------------- > <argo_tec gmbh> > ed.q.bridges > tel. 089-368179.552 > fax 089-368179.79 > osterwaldstraße 10 > (haus F eingang 21) > 80805 münchen > </argo_tec gmbh> > -------------------------------------------- > > > > _______________________________________________ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user