This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have two tables....The autogenerated key of the first one which is also the primary key is the foreign key in the second one. Can u please tell me how do i get the id generated from the first table when I insert the record in it thanks in advance gaurav firstname.lastname@example.org
some of the new drivers that implement the JDBC 3.0 interface have a Statement.getGeneratedKeys() method. Otherwise, you are looking at doing something like mentioned above or create your own autogenerated key using a millisecond date representation( long datatype ) as the key. Jamie
The preferred way would be JDBC 3.0 getGeneratedKeys(), but usually there is also database-specific syntax to get the last key generated in the current transaction; eg SELECT @@IDENTITY on SQL Server. You would execute this as you would any SQL query. - Peter