[英]“Unknown data type” error in jdbc call
I'm trying to call a Postgres function in Java using a Callable Statement. 我正在尝试使用Callable语句在Java中调用Postgres函数。 One of the input parameter to the function is of type Timestamp. 该函数的输入参数之一是时间戳类型。 when I try to call the function from java, I get the following error. 当我尝试从Java调用函数时,出现以下错误。
ERROR: function insrt_data(character varying, integer, bigint, unknown, character varying) does not exist
My function signature is: 我的功能签名是:
insrt_data(
i_cd character varying,
i_prog_id smallint,
i_stat_id bigint,
i_dt date,
i_stat_cd character varying) RETURNS character varying
My jdbc call is as below. 我的jdbc调用如下。 StrtDt is a java.util.Date field. StrtDt是java.util.Date字段。
String sql = "{call mySchema.insrt_data(?, ?, ?, ?, ?)}";
java.sql.Date StartDt = new java.sql.Date(record.getStrtDt().getTime());
Map<String, Object> map = jdbcTemplate.call(connection -> {
CallableStatement statement = connection.prepareCall(sql);
statement.setString(1, record.getCd());
statement.setInt(2, record.getProgId());
statement.setLong(3, record.getId());
statement.setDate(4, StartDt);
statement.setString(5, record.getStatCd());
statement.registerOutParameter(1, Types.VARCHAR);
return statement;
}, paramList);
The issue was with the i_prog_cd
. 问题出在i_prog_cd
。 The function expects a smallint
as value while I was passing an int
. 在传递int
时,该函数期望将smallint
作为值。 Postgres's smallint
corresponds to short
in java. Postgres的smallint
对应于Java中的short
。 After changing it to short
, the code worked! 将其更改为short
,代码就可以了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.