[英]calling a parameterized function in a preparedstatement
I am attempting to use a jdbc preparedstatement to insert data into a sql server 2008 database. 我试图使用jdbc preparedstatement将数据插入到sql server 2008数据库中。 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.
我遇到的困难是我有可能发生变化的时间点ID,我需要根据插入的其他元素查找常量ID。 I have written a stored function to perform the lookup, myIDLookup(x,y).
我编写了一个存储函数来执行查找,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. 我已经看到成功使用内置函数(例如now())的示例,但是在预备语句中没有看到任何关于使用参数化函数的内容。 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. 我认为正确的做法是编写一个存储过程来插入带有x和y的行,并通过调用myIDLookup广告生成id,然后插入行。 A template may look like :
模板可能如下所示:
stored proc insertRow (x, y, z)
{
id = myIDLookup(x , y)
insert into table values (id, x , y, z)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.