用Java编写存储函数(JDBC)

时间:2018-05-31 14:33:01

标签: java sql hive callable-statement

在尝试测试java中的可调用过程时,我在尝试调用报告给定输入参数符号的存储过程时遇到错误(int)

    CallableStatement cstmt = con.prepareCall("{CALL sign(?,"+testVal+")}");
    cstmt.registerOutParameter(1, Types.INTEGER);

stacktrace读取:

    java.sql.SQLException: [Cloudera][JDBC](11420) Error, parameter metadata not populated.
at com.cloudera.hiveserver2.exceptions.ExceptionConverter.toSQLException(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.SPreparedStatement.<init>(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.SCallableStatement.<init>(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common4.C4SCallableStatement.<init>(Unknown Source)
at com.cloudera.hiveserver2.jdbc.jdbc41.S41CallableStatement.<init>(Unknown Source)
at com.cloudera.hiveserver2.jdbc.jdbc41.JDBC41ObjectFactory.createCallableStatement(Unknown Source)
at com.cloudera.hiveserver2.hive.jdbc41.HiveJDBC41ObjectFactory.createCallableStatement(Unknown Source)
at com.cloudera.hiveserver2.jdbc.common.SConnection.prepareCall(Unknown Source)
at TestMethods.callableStatement(TestMethods.java:263)
at HiveJdbcGeneralTest.testTableCreation(HiveJdbcGeneralTest.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at 

1 个答案:

答案 0 :(得分:0)

从错误消息我认为您正在尝试为Hive编写存储过程。 在这种情况下,您可以看到HPL / SQL!= PL / SQL。 可以找到存储过程的正确语法here