Reputation: 11
I am attempting to use a jdbc preparedstatement to insert data into a sql server 2008 database. The difficulty I'm running into is that I have point-in-time IDs which are subject to change, and I need to look up the constant ID based on other elements of the insert. I have written a stored function to perform the lookup, myIDLookup(x,y).
I tried writing a preparedstatement like this:
INSERT INTO myTable (id,idElement1,idElement2,otherItem)
VALUES (myIDLookup(?,?),?,?,?)
I have seen examples successfully using built in functions such as now(), but haven't seen anything about using parameterized functions in a preparedstatement. Is this possible?
Thanks
Upvotes: 1
Views: 389
Reputation: 24791
I think the right way of doing this is to write a stored proc to insert rows that takes x and y and generates the id by calling myIDLookup ad then inserts the row too. A template may look like :
stored proc insertRow (x, y, z)
{
id = myIDLookup(x , y)
insert into table values (id, x , y, z)
}
Upvotes: 3