【问题标题】:java postgresql- No function matches the given name and argument types. You might need to add explicit type castsjava postgresql-没有函数与给定的名称和参数类型匹配。您可能需要添加显式类型转换
【发布时间】:2016-01-18 00:55:49
【问题描述】:

我在postgresql中有一个存储过程如下:

CREATE OR REPLACE FUNCTION insert_orderline(order_id integer, prod_id integer, prodname text, rate numeric, ordered_qty numeric, dispatched_qty numeric, balance_qty numeric, photonum text, remarks text, create_station_id integer, create_stationtype text, create_time text, create_user_id integer, tran_time text, tran_user_id integer)
  RETURNS void AS
$BODY$
   INSERT INTO bakingfactory.orderline
     (orderline_id, order_id, prod_id, prodname, rate, ordered_qty, 
       dispatched_qty, balance_qty, photonum, remarks, create_station_id, 
       create_stationtype, create_time, create_user_id, tran_time, tran_user_id)
   values 
     (default,order_id, prod_id, prodname, rate, ordered_qty, 
       dispatched_qty, balance_qty, photonum, remarks, create_station_id, 
       create_stationtype, create_time, create_user_id, tran_time, tran_user_id) 
$BODY$
  LANGUAGE sql VOLATILE
  COST 100;
ALTER FUNCTION insert_orderline(integer, integer, text, numeric, numeric, numeric, numeric, text, text, integer, text, text, integer, text, integer)
  OWNER TO postgres;

我正在尝试使用 java 插入它,如下所示:

CallableStatement cstorderline = conn.prepareCall("{call insert_orderline(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
                            cstorderline.setInt(1, lastinsertid);
                            cstorderline.setInt(2, prodid);
                            cstorderline.setString(3, proname);
                            cstorderline.setDouble(4, rate);
                            cstorderline.setDouble(5, ordered_qty);
                            cstorderline.setDouble(6, dispatched_qty);
                            cstorderline.setDouble(7, balanced_qty);
                            cstorderline.setString(8, photonum);
                            cstorderline.setString(9, notes);
                            cstorderline.setInt(10, create_station_id);
                            cstorderline.setString(11, create_station_type);
                            cstorderline.setString(12, timewithmilsec);
                            cstorderline.setInt(13, create_user_id);
                            cstorderline.setString(14, timewithmilsec);
                            cstorderline.setInt(15, trans_user_id); 
                            cstorderline.executeUpdate();

我收到如下错误:

org.postgresql.util.PSQLException: ERROR: function bakingfactory.insert_orderline(integer, integer, character varying, double precision, double precision, double precision, double precision, character varying, character varying, integer, character varying, character varying, integer, character varying, integer) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Position: 15

我的数据库中有 numeric 类型的精度值。对于数字类型,我只是使用double。那是正确的方法吗?

【问题讨论】:

  • @a_horse_with_no_name 哥们看看这个!!
  • 那么,您要插入什么数据?
  • @WeareBorg 我要插入双份。这样对吗?? SetDouble
  • 对于哪个值您会遇到错误,您可以为数字插入双精度值。但是为什么要以这种方式插入值?看起来很马车。
  • 你能推荐一个正确的方法吗?

标签: java postgresql


【解决方案1】:

您的错误有多种解释。

第一个解释

您已经创建了一个函数 insert_orderline,但 Java 代码希望该函数包含在 bakingfactory 架构中(可能您已将 bakingfactory 设置为 Java 应用程序连接用户的默认架构)。

因此,将函数创建为:

CREATE OR REPLACE FUNCTION bakingfactory.insert_orderline

而不是

CREATE OR REPLACE FUNCTION insert_orderline

第二次解释

您应该在函数定义中使用double precision 而不是numeric 数据类型。

【讨论】:

  • 我赌5美元,原因是第一个! :)
  • @Alexandros 根据您的建议进行了更改,但错误仍然存​​在。错误代码指定Position: 15 是线索吗?
猜你喜欢
  • 2020-08-26
  • 1970-01-01
  • 1970-01-01
  • 2021-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多