我想在informix数据库中检索存储过程的结果,这是我的代码:
Connection connection = session.connection();
callableStatement = connection.prepareCall("{? = call my_stored_procedure()}");
***callableStatement.registerOutParameter(1, Types.VARCHAR);***
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.registerOutParameter(3, java.sql.Types.INTEGER);
问题是第一个registerOutParameter
不起作用并抛出此异常:
java.sql.SQLException: [BEA][Informix JDBC Driver]Invalid parameter binding(s)
我该怎么办?
答案 0 :(得分:0)
您似乎不能使用registerOutParameter()
来读取功能结果。您可以使用resultSet,而不是这样:
#!/usr/bin/env jython
# -*- coding: utf8 -*-
import sys
import traceback
from java.sql import DriverManager, Types
from java.lang import Class
Class.forName("com.informix.jdbc.IfxDriver")
FUN_BODY = """CREATE FUNCTION get_ver() RETURNING VARCHAR(200);
RETURN 'ver 1.12';
END FUNCTION;"""
def test_init(db):
c = db.createStatement()
try:
c.execute('DROP FUNCTION get_ver;')
except:
pass
c.execute(FUN_BODY)
def test_call(db):
try:
print("\n\n--------------\ncall...")
proc = db.prepareCall("{ ? = call get_ver() }")
rs = proc.executeQuery()
while (rs.next()):
r = rs.getString(1)
print('result: %s' % (r))
except:
print("there were errors!")
s = traceback.format_exc()
sys.stderr.write("%s\n" % (s))
def test_exec(db):
try:
print("\n\n--------------\nEXECUTE PROCEDURE...")
c = db.createStatement()
rs = c.executeQuery("EXECUTE PROCEDURE get_ver()")
while (rs.next()):
r = rs.getString(1)
print('result: %s' % (r))
except:
print("there were errors!")
s = traceback.format_exc()
sys.stderr.write("%s\n" % (s))
def test(db_url, usr, passwd):
print("\n\n%s\n" % (db_url))
db = DriverManager.getConnection(db_url, usr, passwd)
test_init(db)
test_call(db)
test_exec(db)
db.close()
test('jdbc:informix-sqli://test-informix:9088/testifx:informixserver=ol_testifx;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250', 'user', 'passwd')
test('jdbc:odbc:[system_dsn]', 'user', 'passwd')
我的结果:
jdbc:informix-sqli://test-informix....
--------------
call...
result: ver 1.12
--------------
EXECUTE PROCEDURE...
result: ver 1.12