目前我在DAO类中通过JDBC获取postgresql函数数据时遇到问题。连接正在建立。
CallableStatement mngStatement = conn
.prepareCall("{? = CALL SELECT_SEARCH_DETAILS(?,?,?,?,?,?,?,?)}");
mngStatement.registerOutParameter(1, Types.VARCHAR);
mngStatement.setString(2,abc.getContractNumber());
mngStatement.setString(3,abc.getOrderNumber());
mngStatement.setString(4,abc.getShipmentNumber());
mngStatement.setString(5,abc.getShipmentControlNo());
mngStatement.setString(6,abc.getStatusFromDate());
mngStatement.setString(7,abc.getStatusToDate());
mngStatement.setString(8,abc.getSourceSystem());
mngStatement.setString(9,abc.getDestinationSystem());
mngStatement.execute();
rs = (ResultSet) mngStatement.getObject(1);
得到如下错误:
org.postgresql.util.PSQLException:格式错误的函数或过程 偏移量为1的转义语法。
请帮我解决你的建议。在此先感谢。
功能:
FUNCTION SELECT_SEARCH_DETAILS(
IN P_CONTARCT_NUM character varying,
IN P_ORDER_NUM character varying,
IN P_SHIPMENT_NUM character varying,
IN P_SHIP_CON_NUM character varying,
IN P_FROM_DATE character varying,
IN P_TO_DATE character varying,
IN P_SOURCE_SYSTEM character varying,
IN P_DESTINATION_SYSTEM character varying)
RETURNS table(CONTRACT_NUMBER text,ORDER_NUMBER text, SHIPMENT_NUMBER text, SCN text, STATUS_CODE text,STATUS_DATE text, LAST_UPDATE_DATE text, SOURCE_SYSTEM text, DESTINATION_SYSTEM text, RFID_FOLLOW_ON_CODE text, UID_INDICATOR text, IVC_SHIPMENT_SEQ_ID text) AS
$BODY$
答案 0 :(得分:0)
您不需要CallableStatement
。
使用常规PreparedStatement
和select
语句。
当您的函数返回一个表(“set”)时,您需要使用:
select * from SELECT_SEARCH_DETAILS(...);
所以完整代码如下所示:
PreparedStatement pstmt = conn.prepareStatement("select * from SELECT_SEARCH_DETAILS(?,?,?,?,?,?,?,?)");
pstmt.setString(1, abc.getContractNumber());
pstmt.setString(2, abc.getOrderNumber());
pstmt.setString(3, abc.getShipmentNumber());
pstmt.setString(4, abc.getShipmentControlNo());
pstmt.setString(5, abc.getStatusFromDate());
pstmt.setString(6, abc.getStatusToDate());
pstmt.setString(7, abc.getSourceSystem());
pstmt.setString(8, abc.getDestinationSystem());
ResultSet rs = pstmt.executeQuery();