简体   繁体   中英

calling a parameterized function in a preparedstatement

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

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM