我得到一个"无效的SQL语句"我尝试使用 StoredProcedureQuery (JPA / JPQL)调用 MaxDB DBPROC(存储过程)时出现异常。这不是正确的方法吗?
Java环境:
> <persistence-unit name="CAMPAIGN_AD_UNIT_Test"
> transaction-type="RESOURCE_LOCAL">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
> <properties>
> <property name="javax.persistence.jdbc.driver" value="com.sap.dbtech.jdbc.DriverSapDB" />
> <property name="javax.persistence.jdbc.url" value="jdbc:sapdb://localhost/MAXDB" />
> <property name="javax.persistence.jdbc.user" value="ST" />
> <property name="javax.persistence.jdbc.password" value="*********" />
> <property name="eclipselink.target-database" value="MaxDB"/>
> <property name="eclipselink.ddl-generation" value="none" />
> </properties> </persistence-unit>
// StoredProcedureCall
StoredProcedureQuery spQuery = jem.createStoredProcedureQuery("ST.TESTPROC");
spQuery.registerStoredProcedureParameter("CAMPAIGNS", Integer.class, ParameterMode.OUT);
try {
tx.begin();
boolean success = spQuery.execute();
System.out.println("execute : " + success);
Object obj = spQuery.getOutputParameterValue("CAMPAIGNS");
tx.commit();
System.out.println("result: " + String.valueOf(obj));
} catch (RuntimeException e) {
// roll back
if (tx != null && tx.isActive())
tx.rollback();
throw e;
}
&#13;
[EL Warning]: 2015-04-16 15:17:33.06--UnitOfWork(1891955695)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.sap.dbtech.jdbc.exceptions.jdbc40.SQLSyntaxErrorException: [-3005]: Invalid SQL statement
Error Code: -3005
Call: EXECUTE PROCEDURE TESTPROC(CAMPAIGNS = ?)
bind => [1 parameter bound]
Query: ResultSetMappingQuery()
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.sap.dbtech.jdbc.exceptions.jdbc40.SQLSyntaxErrorException: [-3005]: Invalid SQL statement
Error Code: -3005
Call: EXECUTE PROCEDURE TESTPROC(CAMPAIGNS = ?)
bind => [1 parameter bound]
Query: ResultSetMappingQuery()
at org.eclipse.persistence.internal.jpa.QueryImpl.getDetailedException(QueryImpl.java:382)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:260)
at org.eclipse.persistence.internal.jpa.StoredProcedureQueryImpl.execute(StoredProcedureQueryImpl.java:316)
at de.homemade.education.jpa.Main.main(Main.java:80)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.sap.dbtech.jdbc.exceptions.jdbc40.SQLSyntaxErrorException: [-3005]: Invalid SQL statement
Error Code: -3005
Call: EXECUTE PROCEDURE TESTPROC(CAMPAIGNS = ?)
bind => [1 parameter bound]
...
&#13;
MaxDB DBPROC SQL
> CREATE DBPROCEDURE ST.TESTPROC (OUT CAMPAIGNS INTEGER) AS
> TRY
> DECLARE MYCURSOR CURSOR FOR
> SELECT COUNT(CAMPAIGN) FROM ST.CAMPAIGN_AD;
> FETCH MYCURSOR INTO :CAMPAIGNS;
> CATCH
> BEGIN
> STOP ($RC, 'unexpected error');
> CLOSE MYCURSOR;
> END;
>
> Test in SQL Studio / SQL Dialog:
>
> call TESTPROC(?)
>
> result: | Out(1) 1 | 1