PSQLException,没有函数匹配给定的名称和参数类型

时间:2015-08-05 02:47:43

标签: java postgresql stored-procedures jdbc

我对postgres中的函数完全不熟悉。在过去的几天里,我一直在努力解决这个问题。

org.postgresql.util.PSQLException: ERROR: function create_new_user(bigint, character varying, character varying, character varying, character varying, unknown, character) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.
  Position: 15
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:413)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)

这是我尝试运行以下代码时遇到的异常:

    Connection conn = this.dataSource.getConnection();
    CallableStatement statement = conn.prepareCall("{ ? = call create_new_user(?,?,?,?,?,?,?)}");
    statement.registerOutParameter(1, Types.BOOLEAN);
    statement.setLong(2, oAuthAccountId);
    statement.setString(3, oAuthSigninProvider);
    statement.setString(4, firstName);
    statement.setString(5, lastName);
    statement.setString(6, email);
    statement.setDate(7, dateOfBirth);
    statement.setObject(8, gender, Types.CHAR);
    return statement.execute();

似乎问题在于dateOfBirth值。它的类型为java.sql.Date。当我检查语句的值时,会生成以下内容:

select * from create_new_user(?,123456789,'facebook','firstName','lastName','me@site.com','1985-02-08 -05:00:00','m')  as result

postgres功能

CREATE FUNCTION create_new_user (p_oauth_account_id bigint, p_oauth_signin_provider text, p_first_name text, p_last_name text, p_email text, p_date_of_birth date, p_gender character)
RETURNS boolean AS 
$$
BEGIN
    INSERT INTO users(oauth_account_id, oauth_signin_provider, first_name, last_name, email, date_of_birth, gender, date_joined, is_enabled) 
    VALUES($1,$2,$3,$4,$5,$6,$7,NOW(),true) 
    LIMIT 1;
END;
$$
LANGUAGE 'plpgsql';

0 个答案:

没有答案