使用CallableStatement调用HSQLDB IDENTITY函数以获取输出 [英] Calling HSQLDB IDENTITY function with CallableStatement to get output
问题描述
我正在尝试使用CallableStatements从Java JDBC获取HSQLDB中IDENTITY()的值.
I'm trying to use CallableStatements to get the value of IDENTITY() in HSQLDB from Java JDBC.
我可以准备好打电话.问题出在registerOutputParameter上.无论传入什么索引,我都会得到参数索引超出范围".
I can prepareCall fine. The issue is with registerOutputParameter. I get "parameter index out of range" no matter what index I pass in.
我尝试过"{?= CALL IDENTITY()}"之类的SQL代码片段,但是没有运气.
I've tried SQL snippets like "{? = CALL IDENTITY()}" with no luck.
有任何线索吗?我是否完全无法从JDBC调用HSQLDB函数例程?
Any clues? Am I completely off track in how to invoke HSQLDB function routines from JDBC?
推荐答案
Instead of using IDENTITY()
, use getGeneratedKeys()
to retrieve any keys generated by the (insert) statement.
请注意,您确实需要使用启用此功能的Statement.execute...
或Connection.prepare...
方法之一.
Note that you do need to use one of the Statement.execute...
or Connection.prepare...
methods that will enable this feature.
这篇关于使用CallableStatement调用HSQLDB IDENTITY函数以获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!