anyone know a good way to return the identity of a row that was just inserted?
Daniel Dunleavy
Ranch Hand
Joined: Mar 13, 2001
Posts: 276
posted
0
if you are talking about MS SQL SERVER.... you should call a stored procedure which does the insert and the last statement in the procedure is select @@IDENTITY Dan
Originally posted by jesse harris: anyone know a good way to return the identity of a row that was just inserted?
Another idea that works with oracle(it may be possible in SQLServer too) is to use a select statement to obtain the new identifier. In Oracle the database will give out the next available id (as if it were in an insert statement) then use the id in your insert statement. Oracle code: resultset = statement.executeQuery("select sequence.nextVal from dual"); long nextId = resultset.getLong(1); --> this selects the next id value from the database. dual is just a dummy table so you can accomplish the select statement. statement.executeUpdate("insert into table (id, name) values (" + nextId + ", 'Joey Joe Joe Shabadoo')"); Jamie
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.