Thread: issues with java driver setDate() on function call

issues with java driver setDate() on function call

From
"Ismael ...."
Date:
I have a function declared as follows
CREATE OR REPLACE FUNCTION insertaegreso(usuario1 integer, importepago1 numeric, fechapago1 DATE, concepto1 character
varying,tipopagonomina1 character varying, comentarios1 character varying) 
RETURNS integer AS....implementation....

notice the field "fechapago1 DATE"

the function is working just fine, I tried it from pgadmin3 and it works,
but when I try to call it using java's PreparedStatement pst;
pst.setDate(3, date);
I get this error, (note: "no existe la función" means "the function .... doesn't exists")

org.postgresql.util.PSQLException: ERROR: no existe la función insertaegreso(integer, double precision, unknown,
charactervarying, character varying, character varying) 

it puts "unknown" instead of date


is there a workaround for it that doesn't involve creating a function with VARCHAR instead of DATE?


because also when I try to do something like

String sql1 = "SELECT EXTRACT (YEAR FROM ?)";
PreparedStatement pst = con.getPreparedStatement(sql1);
pst.setDate(1, date);

I get this error:

(the function....isn't unique)
org.postgresql.util.PSQLException: ERROR: la función pg_catalog.date_part(unknown, unknown) no es única


tanks in advance
_________________________________________________________________
Plug&Play te trae en exclusiva los mejores conciertos de la red
http://club.prodigymsn.com/

Re: issues with java driver setDate() on function call

From
"Ismael ...."
Date:
sorry, just discovered the answer, only need to cast the value like this
....
String sql = "SELECT * FROM insertaEgreso(?, ?, ?::DATE, ?, ?, ?)";
....
pst.setDate(3, date);
....
:)



>
>
> I have a function declared as follows
> CREATE OR REPLACE FUNCTION insertaegreso(usuario1 integer, importepago1 numeric, fechapago1 DATE, concepto1 character
varying,tipopagonomina1 character varying, comentarios1 character varying) 
> RETURNS integer AS....implementation....
>
> notice the field "fechapago1 DATE"
>
> the function is working just fine, I tried it from pgadmin3 and it works,
> but when I try to call it using java's PreparedStatement pst;
> pst.setDate(3, date);
> I get this error, (note: "no existe la función" means "the function .... doesn't exists")
>
> org.postgresql.util.PSQLException: ERROR: no existe la función insertaegreso(integer, double precision, unknown,
charactervarying, character varying, character varying) 
>
> it puts "unknown" instead of date
>
>
> is there a workaround for it that doesn't involve creating a function with VARCHAR instead of DATE?
>
>
> because also when I try to do something like
>
> String sql1 = "SELECT EXTRACT (YEAR FROM ?)";
> PreparedStatement pst = con.getPreparedStatement(sql1);
> pst.setDate(1, date);
>
> I get this error:
>
> (the function....isn't unique)
> org.postgresql.util.PSQLException: ERROR: la función pg_catalog.date_part(unknown, unknown) no es única
>
>
> tanks in advance
> _________________________________________________________________
> Plug&Play te trae en exclusiva los mejores conciertos de la red
> http://club.prodigymsn.com/
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

_________________________________________________________________
Plug&Play te trae en exclusiva los mejores conciertos de la red
http://club.prodigymsn.com/

Re: issues with java driver setDate() on function call

From
Tom Lane
Date:
"Ismael ...." <ismaelpsp@hotmail.com> writes:
> I have a function declared as follows
> CREATE OR REPLACE FUNCTION insertaegreso(usuario1 integer, importepago1 numeric, fechapago1 DATE, concepto1 character
varying,tipopagonomina1 character varying, comentarios1 character varying) 
> RETURNS integer AS....implementation....

> but when I try to call it using java's PreparedStatement pst;
> I get this error, (note: "no existe la funci�n" means "the function .... doesn't exists")
> org.postgresql.util.PSQLException: ERROR: no existe la funci�n insertaegreso(integer, double precision, unknown,
charactervarying, character varying, character varying) 

Actually I think your problem is with the *second* parameter.  There is
no implicit cast from double precision to numeric.

            regards, tom lane