使用CallableStatement调用HSQLDB IDENTITY函数以获取输出 [英] Calling HSQLDB IDENTITY function with CallableStatement to get output

查看:112
本文介绍了使用CallableStatement调用HSQLDB IDENTITY函数以获取输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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?

推荐答案

代替使用IDENTITY(),而使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆