Home > Archive > PostgreSQL JDBC > November 2005 > passing parameters to function









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author passing parameters to function
Srivats

2005-11-08, 4:12 pm


Hi All,

Suppose I have a store proc which accepts 4 input parameters
and I do a CallableStatement.setObject( 1, "..,,," );
and execute the query .


CallableStatement functionCall = dbCon_.prepareCall("{call test1( ?,?,?,?) }");
functionCall.setObject( "param1","A10001" );
functionCall.setObject( "param2","19830529" );
functionCall.execute();

Exception raised

java.sql.SQLException: No value specified for parameter 3
at com.mysql.jdbc.PreparedStatement. fillSendPacket(Prepa
redStatement.java:1253)
at com.mysql.jdbc.PreparedStatement. fillSendPacket(Prepa
redStatement.java:1201)
at com.mysql.jdbc.PreparedStatement. execute(PreparedStat
ement.java:710)
at com.mysql.jdbc.CallableStatement. execute(CallableStat
ement.java:520)


during runtime. Should i set the other 2 input parameters to null,
even when I dont want to pass these parameters to the SP.
In this statement call test1( ?,?,?,?), should the number of parameters be the number
of parameters which the store procedure accepts or the number of parameters that i want
to pass. How should this be done when my SP accepts 4 parameters and i want to pass
only any two of them

Thks

PS: Looking for an early reply





Dave Cramer

2005-11-08, 4:12 pm

You would have to set them to NULL

Dave
On 8-Nov-05, at 7:31 AM, Srivats wrote:

>
> Hi All,
>
> Suppose I have a store proc which accepts 4 input parameters
> and I do a CallableStatement.setObject( 1, "..,,," );
> and execute the query .
>
>
> CallableStatement functionCall = dbCon_.prepareCall("{call test1
> ( ?,?,?,?) }");
> functionCall.setObject( "param1","A10001" );
> functionCall.setObject( "param2","19830529" );
> functionCall.execute();
> Exception raised
>
> java.sql.SQLException: No value specified for parameter 3
> at com.mysql.jdbc.PreparedStatement.fillSendPacket
> (PreparedStatement.java:1253)
> at com.mysql.jdbc.PreparedStatement.fillSendPacket
> (PreparedStatement.java:1201)
> at com.mysql.jdbc.PreparedStatement.execute
> (PreparedStatement.java:710)
> at com.mysql.jdbc.CallableStatement.execute
> (CallableStatement.java:520)
>
>
> during runtime. Should i set the other 2 input parameters to null,
> even when I dont want to pass these parameters to the SP.
> In this statement call test1( ?,?,?,?), should the number of
> parameters be the number
> of parameters which the store procedure accepts or the number of
> parameters that i want
> to pass. How should this be done when my SP accepts 4 parameters
> and i want to pass
> only any two of them
>
> Thks
>
> PS: Looking for an early reply
>
>
>
>
>
>



Srivats

2005-11-09, 3:24 am

Hi All,

Is there anyway i can get the list of parameters which the store proc accepts from the java end after i make the prepareCall.

Thks

----- Original Message -----
From: Dave Cramer
To: Srivats
Cc: pgsql-jdbc@postgresql.org
Sent: Tuesday, November 08, 2005 9:21 PM
Subject: Re: [JDBC] passing parameters to function


You would have to set them to NULL


Dave

On 8-Nov-05, at 7:31 AM, Srivats wrote:



Hi All,

Suppose I have a store proc which accepts 4 input parameters
and I do a CallableStatement.setObject( 1, "..,,," );
and execute the query .


CallableStatement functionCall = dbCon_.prepareCall("{call test1( ?,?,?,?) }");
functionCall.setObject( "param1","A10001" );
functionCall.setObject( "param2","19830529" );
functionCall.execute();

Exception raised

java.sql.SQLException: No value specified for parameter 3
at com.mysql.jdbc.PreparedStatement. fillSendPacket(Prepa
redStatement.java:1253)
at com.mysql.jdbc.PreparedStatement. fillSendPacket(Prepa
redStatement.java:1201)
at com.mysql.jdbc.PreparedStatement. execute(PreparedStat
ement.java:710)
at com.mysql.jdbc.CallableStatement. execute(CallableStat
ement.java:520)


during runtime. Should i set the other 2 input parameters to null,
even when I dont want to pass these parameters to the SP.
In this statement call test1( ?,?,?,?), should the number of parameters be the number
of parameters which the store procedure accepts or the number of parameters that i want
to pass. How should this be done when my SP accepts 4 parameters and i want to pass
only any two of them

Thks

PS: Looking for an early reply









Achilleus Mantzios

2005-11-09, 3:24 am

O Srivats έγραψε στις Nov 9, 2005 :

> Hi All,
>
> Is there anyway i can get the list of parameters which the store proc accepts from the java end after i make the prepareCall.


You might want to look at
DatabaseMetaData dbmd = con.getMetaData();
ResultSet your_funk_args = dbmd. getProcedureColumns(
...);
I dont know (or looked) if it is supported by the current
7.4 pgsql jdbc.

>
> Thks
>
> ----- Original Message -----
> From: Dave Cramer
> To: Srivats
> Cc: pgsql-jdbc@postgresql.org
> Sent: Tuesday, November 08, 2005 9:21 PM
> Subject: Re: [JDBC] passing parameters to function
>
>
> You would have to set them to NULL
>
>
> Dave
>
> On 8-Nov-05, at 7:31 AM, Srivats wrote:
>
>
>
> Hi All,
>
> Suppose I have a store proc which accepts 4 input parameters
> and I do a CallableStatement.setObject( 1, "..,,," );
> and execute the query .
>
>
> CallableStatement functionCall = dbCon_.prepareCall("{call test1( ?,?,?,?) }");
> functionCall.setObject( "param1","A10001" );
> functionCall.setObject( "param2","19830529" );
> functionCall.execute();
>
> Exception raised
>
> java.sql.SQLException: No value specified for parameter 3
> at com.mysql.jdbc.PreparedStatement. fillSendPacket(Prepa
redStatement.java:1253)
> at com.mysql.jdbc.PreparedStatement. fillSendPacket(Prepa
redStatement.java:1201)
> at com.mysql.jdbc.PreparedStatement. execute(PreparedStat
ement.java:710)
> at com.mysql.jdbc.CallableStatement. execute(CallableStat
ement.java:520)
>
>
> during runtime. Should i set the other 2 input parameters to null,
> even when I dont want to pass these parameters to the SP.
> In this statement call test1( ?,?,?,?), should the number of parameters be the number
> of parameters which the store procedure accepts or the number of parameters that i want
> to pass. How should this be done when my SP accepts 4 parameters and i want to pass
> only any two of them
>
> Thks
>
> PS: Looking for an early reply
>
>
>
>
>
>
>
>
>


--
-Achilleus


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com