Re: [INTERFACES] JDBC and getting just assigned serial number
От | Peter Mount |
---|---|
Тема | Re: [INTERFACES] JDBC and getting just assigned serial number |
Дата | |
Msg-id | Pine.LNX.4.10.9909141825540.543-100000@maidast.retep.org.uk обсуждение исходный текст |
Ответ на | JDBC and getting just assigned serial number (Christoph Steinbeck <steinbeck@ice.mpg.de>) |
Список | pgsql-interfaces |
On Mon, 13 Sep 1999, Christoph Steinbeck wrote: > Hi, > > I'm thrilled to see that there is some kind of discussion running in the > C area on the exact equivalent of my very recent JDBC problem. > I insert a row into a table where one field is a SERIAL. This SERIAL, of > course, is automatically assigned by PostgreSQL. How do I get this > number immeadiately after inserting the row? When I issue the command > with psql I get back some kind of number which presumably is the OID. > Getting just this one would be fine too because I need it for > referencing. There's not a standard way, but we do have an extension method that does the job: getResultStatusString() This method was added as someone else asked for it in the distant past. ie: Statement st = conn.createStatement(); .. your code that either runs st.executeQuery() or st.executeUpdate() .. then for JDK1.1.x: String returncode = ((postgresql.jdbc1.Statement)st).getResultStatusString(); or for Java2:String returncode = ((postgresql.jdbc2.Statement)st).getResultStatusString(); PS: Sorry, you have to state the driver version (jdbc1 or jdbc2), although this will be fixed in 6.6, and will become postgresql.Statement. Peter -- Peter T Mount peter@retep.org.uk Main Homepage: http://www.retep.org.uk PostgreSQL JDBC Faq: http://www.retep.org.uk/postgresJava PDF Generator: http://www.retep.org.uk/pdf
В списке pgsql-interfaces по дате отправления: