Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Retrieving ROWID during INSERT in JDBC?
In article <Xns918DB485767F2walkerbohshymailcom_at_204.127.202.16>, Walker says...
>
>
>Is it possible to retrieve the ROWID of a newly inserted row during the
>INSERT operation using JDBC?
>
>I saw an example on the Oracle docs using PL/SQL and a syntax similar
>to the following (inside a procedure):
>
>INSERT INTO table VALUES( x, y ) RETURNING ROWID INTO rID
>
>But I haven't been able to make this work from within JDBC. Any ideas?
>
>I'm using 8i (8.1.7) and 9i and JDK 1.2.
>
import java.sql.*;
import java.util.*;
class spString {
public static void main (String args[]) throws SQLException {
DriverManager.registerDriver
(new oracle.jdbc.driver.OracleDriver());
Connection con =
DriverManager.getConnection ("jdbc:oracle:thin:@aria-dev:1521:ora817dev", "scott", "tiger"); CallableStatement stmt = con.prepareCall("begin "+ "insert into t (x) values (1) "+ "returning rowid into ?;"+ "end;");
stmt.registerOutParameter(1, Types.VARCHAR);
stmt.execute();
System.out.println( "Returned value = " + stmt.getString(1) );
}
}
I myself would prefer to use a stored procedure that hides all of this, just make it a function or procedure -- pass inputs, get outputs.
-- Thomas Kyte (tkyte@us.oracle.com) http://asktom.oracle.com/ Expert one on one Oracle, programming techniques and solutions for Oracle. http://www.amazon.com/exec/obidos/ASIN/1861004826/ Opinions are mine and do not necessarily reflect those of Oracle CorpReceived on Sun Jan 06 2002 - 09:41:20 CST