java CallableOrg。postgresql。util。日期参数未知的PSQLException
我使用CallableStatement类执行Postgres过程。然而,它抛出了PSQLException异常。 请参阅下面的java代码和日志
Java代码:
reCalculateBalance(null, account.getId(), DateUtils.localDateToDate(account.getDateOfInitialBalance()));
private void reCalculateBalance(BigInteger transactionId, BigInteger accountId, java.sql.Date startingDate) {
log.info("start call sp_balance_calculation: transactionId {}, accountId {}, startingDate {}", transactionId, accountId, startingDate);
Session session = entityManager.unwrap(Session.class);
String result = session.doReturningWork(
connection -> {
try (CallableStatement function = connection.prepareCall("call core.sp_balance_calculation(?,?,?,?)" )) {
if (transactionId == null) {
function.setNull(1, Types.BIGINT);
} else {
function.setObject(1, transactionId, Types.BIGINT);
}
if (accountId == null) {
function.setNull(2, Types.BIGINT);
} else {
function.setLong(2, accountId.longValue());
}
function.setDate( 3, startingDate);
function.registerOutParameter(4, Types.VARCHAR);
function.execute();
return function.getString( 4 );
}
} );
log.info("result = {}", result);
session.close();
}
日志:
15:28:15.830 [http-nio-8082-exec-1] INFO c.c.c.a.d.s.impl.AccountServiceImpl - start call sp_balance_calculation: transactionId null, accountId 37, startingDate 2020-05-27
15:28:15.836 [http-nio-8082-exec-1] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 42883
15:28:15.836 [http-nio-8082-exec-1] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: procedure core.sp_balance_calculation(bigint, bigint, unknown) does not exist
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts.
Position: 6
15:28:15.845 [http-nio-8082-exec-1] ERROR c.c.c.a.a.v.e.RestEndpointExceptionHandler - ERROR: procedure core.sp_balance_calculation(bigint, bigint, unknown) does not exist
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts.
Position: 6
org.hibernate.exception.SQLGrammarException: error executing work
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:103)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:311)
at org.hibernate.internal.AbstractSharedSessionContract.doWork(AbstractSharedSessionContract.java:1084)
at org.hibernate.internal.AbstractSharedSessionContract.doReturningWork(AbstractSharedSessionContract.java:1080)
at cash.continuity.cc.api.db.service.impl.AccountServiceImpl.reCalculateBalance(AccountServiceImpl.java:114)
at cash.continuity.cc.api.db.service.impl.AccountServiceImpl.createAccount(AccountServiceImpl.java:106)
at cash.continuity.cc.api.db.service.impl.AccountServiceImpl$$FastClassBySpringCGLIB$$f65d7c8c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
程序:sp_平衡计算
core.sp_balance_calculation (
IN p_transaction_id BIGINT,
IN p_account_id BIGINT,
IN p_starting_date DATE,
INOUT p_error_code VARCHAR
)
似乎日期字段的转换不正确,但在查看日志时,我看到输入通常为:transactionId=null,accountId=37,startingDate='2020-05-27'。 请帮我检查为什么它会抛出未知的日期字段
# 1 楼答案
我需要设置out参数的值
设置好之后,我就可以从java执行这个过程了