Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C42DF6329D7 for ; Tue, 6 Oct 2009 09:29:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 51944-01 for ; Tue, 6 Oct 2009 12:29:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from qw-out-2122.google.com (qw-out-2122.google.com [74.125.92.24]) by mail.postgresql.org (Postfix) with ESMTP id 578B96324D1 for ; Tue, 6 Oct 2009 09:29:31 -0300 (ADT) Received: by qw-out-2122.google.com with SMTP id 9so1223934qwb.61 for ; Tue, 06 Oct 2009 05:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=65D0szX5kcIb09ORZ3pbIg0IqqLxc/H9jAF4G4FNPjE=; b=tSaUXHGexnKniqTotgAcAsfLFu1h427NBf7VrE8jtNPZl+ufjdMJvevFVKAIitszzN BuOt5iJ9AQ9GjfVLq2hfycUJchwmpW8BW4XZdaNNnpDdRsjUPHXEpOQFsLmf4lQsqV+2 IwfofXjTMtIeccpqjdq8nDVunjs/3IvNKWtIs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=PSuTl1LBytrzCqFaY8su5sf63cjDllb1mk/kbs55tSKWcI+YS/5WOKMQhkyk6udr4S 0xTcfyeKqt+43wPtoETohw+xl/7vah96jyrmu1Q5D7v+4IpqU7gO8SgkJYoKBVOmFzH4 IKTLPdigZiGQpx29WQBwnHJdyb8Vq0KnjVvl0= MIME-Version: 1.0 Received: by 10.229.19.149 with SMTP id a21mr620816qcb.29.1254832169594; Tue, 06 Oct 2009 05:29:29 -0700 (PDT) Date: Tue, 6 Oct 2009 20:29:29 +0800 Message-ID: <272d36040910060529n7325a1ces68cb3a3d025d9149@mail.gmail.com> Subject: callable statement cannot work when call stored procedure @postgres84 From: Ying-Wen Chen To: pgsql-jdbc@postgresql.org Content-Type: multipart/alternative; boundary=0016e64c34c0b8b13404754361dd X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.598 tagged_above=-10 required=5 tests=BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200910/5 X-Sequence-Number: 20007 --0016e64c34c0b8b13404754361dd Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable hi postgres team, I try to call stored function with Postgres84 doc and jdbc but always fails! * First of ALL ,my stored procedure code's as follow:* (It returns recordset when I run "select t.* from fn_getmsgobj(98); at pgAdmin tool, so I think procedure is fine) CREATE OR REPLACE FUNCTION fn_getmsgobj(user_id integer) RETURNS setof dandelion_vermouth AS $BODY$ declare rs record; BEGIN create temp table temp_follower as select * from dblink('host=3D192.168.2.143 dbname=3DGmmyI_Angler01 user=3Dpostgr= es password=3D111111', 'select following_user_id , user_id from angler_playmat= e') as t1(following_user_id integer, host_user_id integer) where host_user_id =3D user_id; FOR rs IN select b.ser_id, b.host_user_id, b.to_user_id,b.content_type,b.content,b.create_time from dandelion_vermouth as b, (select a.host_user_id , max(a.ser_id) as ser_id ,max(a.create_time) from dandelion_vermouth as a, temp_follower as b where a.host_user_id in ( b.following_user_id, b.host_user_id) and a.to_user_id in(0, b.host_user_id) group by a.host_user_id ) as a where a.ser_id =3D b.ser_id ; LOOP RETURN NEXT refcursor; END LOOP; DROP table temp_follower; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100 ROWS 1000; ALTER FUNCTION fn_getmsgobj(integer) OWNER TO postgres; *Second, i use java code to call procedure*. In fact, I tried using hibernate to call stored procedure but it got error all the time, so then alternative way to use JDBC... session =3D HibernateUtil.getSessionFactoryS2().getCurrentSession(); tx =3D session.beginTransaction(); Connection connection =3D session.connection(); connection.setAutoCommit(false); CallableStatement proc =3D connection.prepareCall("{ ? =3D = call fn_getmsgobj(?) }"); proc.setInt(2,98); proc.registerOutParameter(1, Types.OTHER); proc.execute(); ResultSet results =3D (ResultSet) proc.getObject(1); while(results.next()){ System.out.println("okok"); } After running programmer, error accours ... org.postgresql.util.PSQLException: A CallableStatement was executed with an invalid number of parameters at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2S= tatement.java:387) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.= java:360) at com.gmmyi.dao.DandelionDAO.getMsgObj(DandelionDAO.java:389) at com.gmmyi.test.TestMessage.main(TestMessage.java:15) [FATAL] 2009-10-06 20:09:52 com.gmmyi.dao.DandelionDAO - A CallableStatemen= t was executed with an invalid number of parameters 2009/10/6 =E4=B8=8B=E5=8D=88 08:09:52 org.hibernate.impl.SessionFactoryImpl= close I am so preciate someone could help me solve this. By the way, It is ok if I code this ResultSet rs; Connection connection =3D session.connection(); connection.setAutoCommit(false); CallableStatement callableStatement =3D connection.prepareCall("{call fn_getmsgobj(?) }"); callableStatement.setInt(1,user_id); rs =3D callableStatement.executeQuery(); while(rs.next()){ Dandelion_vermouth dvm =3D new Dandelion_vermouth(); dvm.setSer_id(Integer.valueOf(rs.getString("ser_id"))); dvm.setHost_user_id(Integer.valueOf(rs.getString("host_user_id"))); dvm.setTo_user_id(Integer.valueOf(rs.getString("to_user_id"))); dvm.setContent_type(Short.valueOf(rs.getString("content_type"))); dvm.setContent(rs.getString("content")); dvm.setCreate_time(rs.getTimestamp("create_time")); } It really confuses me why getObject(1) cannot work but the doc commends thi= s usage. --=20 Best regard, Olivia.Chen --0016e64c34c0b8b13404754361dd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable hi postgres team,

I try to call stored function with Postgres84 doc = and jdbc=C2=A0 but always fails!

First of ALL ,my stored procedu= re code's as follow:

(It returns recordset when I run "sele= ct t.* from fn_getmsgobj(98); at pgAdmin tool, so I think procedure is fine= )
CREATE OR REPLACE FUNCTION fn_getmsg= obj(user_id integer)
=C2=A0 RETURNS setof dandelion_vermouth AS
$BODY$
declare rs record;
BEGIN=C2=A0=C2=A0=C2=A0
=C2=A0=C2=A0=C2=A0 create temp table= temp_follower as
=C2=A0=C2=A0=C2=A0 select=C2=A0 *
=C2=A0= =C2=A0=C2=A0 from dblink('host=3D192.168.2.143 dbname=3DGmmyI_Angler01 = user=3Dpostgres password=3D111111', 'select following_user_id , use= r_id from angler_playmate') as t1(following_user_id integer, host_user_= id integer)
=C2=A0=C2=A0=C2=A0 where host_user_i= d =3D user_id;

=C2=A0=C2=A0=C2= =A0 FOR rs IN select b.ser_id, b.host_user_id,=C2=A0 b.to_user_id,b.content= _type,b.content,b.create_time=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= =C2=A0=C2=A0
=C2=A0=C2=A0=C2=A0 from dandelion_ve= rmouth as b,
=C2=A0=C2=A0=C2=A0 (select a.host_user_id , max(a.ser_i= d) as ser_id ,max(a.create_time) from dandelion_vermouth as a, temp_followe= r as b where a.host_user_id in ( b.following_user_id, b.host_user_id)=C2=A0= and a.to_user_id in(0, b.host_user_id)=C2=A0=C2=A0=C2=A0=C2=A0 group by a.= host_user_id ) as a
=C2=A0=C2=A0=C2=A0 where a.ser_id = =3D b.ser_id ;
=C2=A0=C2=A0=C2=A0 LOOP
=C2=A0=C2=A0=C2=A0 RET= URN NEXT refcursor;
=C2=A0=C2=A0=C2=A0 END LOOP;<= br style=3D"color: rgb(0, 0, 153);">= =C2=A0=C2=A0=C2=A0 DROP table temp_follower;
END;
$BODY$
=C2=A0 LANGUAGE 'p= lpgsql' VOLATILE
=C2=A0 COST 100
=C2=A0 ROWS 1000;
ALTER FUNCT= ION fn_getmsgobj(integer) OWNER TO postgres;

Second, i use= java code to call procedure.
In fact, I tried using hibernate to call stored procedure but it got error = all the time, so then alternative way to use JDBC...

sessi= on =3D HibernateUtil.getSessionFactoryS2().getCurrentSession();
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 tx =3D session.beginTransaction();
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Conne= ction connection =3D session.connection();
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 connection.= setAutoCommit(false);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CallableStatement proc =3D conne= ction.prepareCall("{ ? =3D call fn_getmsgobj(?) }");
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 proc.setInt(2,98);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 proc.registerOutPara= meter(1, Types.OTHER);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 proc.execute();
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ResultSet results =3D (ResultSet) proc.getObject(1);
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= while(results.next()){
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 System.out.println("okok"= );
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 }


After running programmer, error accou= rs ...
org.postgresql.util.PSQLEx= ception: A CallableStatement was executed with an invalid number of paramet= ers
=C2=A0=C2=A0=C2=A0 at org.postgresql= .jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:= 387)
=C2=A0=C2=A0=C2=A0 at org.postgresql.jdbc2.AbstractJdbc2Stateme= nt.execute(AbstractJdbc2Statement.java:360)
=C2=A0=C2=A0=C2=A0 at com.gmmyi.dao.= DandelionDAO.getMsgObj(DandelionDAO.java:389)
=C2=A0=C2=A0=C2=A0 at = com.gmmyi.test.TestMessage.main(TestMessage.java:15)
[FATAL] 2009-10-06 20:09:52 com.gmmy= i.dao.DandelionDAO - A CallableStatement was executed with an invalid numbe= r of parameters
2009/10/6 =E4=B8=8B=E5=8D=88 08:09:52 org.hibernate.= impl.SessionFactoryImpl close


I am so preciate someone could help me solve this.

By the wa= y, It is ok if I code this
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ResultSet rs;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Co= nnection connection =3D session.connection();
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 connecti= on.setAutoCommit(false);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 CallableStatem= ent callableStatement =3D connection.prepareCall("{call fn_getmsgobj(?= ) }");
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 callable= Statement.setInt(1,user_id);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rs =3D call= ableStatement.executeQuery();

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 while(rs= .next()){
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Dandelion_vermouth dvm =3D new Dandelion_vermouth();
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 dvm.setSer_id(Integer.valueOf(rs.getString("ser_= id")));
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 dvm.setHost_user_id(Integer.valueOf(rs.getString("host_user_id&quo= t;)));
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 dvm.setTo_user_id(Integer.valueOf(rs.getString("= to_user_id")));
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 dvm.setContent_type(Short.valueOf(rs.getString("content_t= ype")));
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 dvm.setContent(rs.getString("content"));
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dvm.setCrea= te_time(rs.getTimestamp("create_time"));
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 }

It really confuses me why getObject(1) cannot work but = the doc commends this usage.



--
Best regar= d,

Olivia.Chen

--0016e64c34c0b8b13404754361dd--