| Author |
multiple inserts with @@identity
|
jdbc stretch
Greenhorn
Joined: Jul 02, 2003
Posts: 1
|
|
help! help, someone! here's the problem mssqlserver.jar (jdbc2.0 compat) t1 is auto-increment primary-key. part of t2's primary key is the @@identity of t1 i want to say: PreparedStatement(" insert into t1 (a,b,c,d) values (?,?,?,?); insert into t2 (e,f,g) values (@@identity,?,?) ") when i run through and set ?1,?2,?3,?4 i'm ok when i set ?6,?7 and ask jdbc to do this for me, it bombs out with InvalidParameterBinding. any thoughts? is this just an impossible task? ****the catch here is that i need to be using addBatch on insert (big, big insert batch) and i don't wanna do the logical equivalent of (insert-into-t1, select identity, insert-into-t2) for each row. this will not meet performance reqs
|
 |
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
|
|
You're not preparing a statement. You're trying to prepare two statements at once. That won't work. Since you're adding them to a batch anyway -- have you tried preparing them as separate statements insert into t1 (a,b,c,d) values (?,?,?,?) insert into t2 (e,f,g) values (@@identity,?,?) And sticking them into your batch, in that order? I don't see why that shouldn't work... - Peter
|
 |
 |
|
|
subject: multiple inserts with @@identity
|
|
|