Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4pPA-0002um-6B for pgsql-jdbc@arkaria.postgresql.org; Mon, 02 Sep 2019 16:42:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i4pP8-0000Gb-Ph for pgsql-jdbc@arkaria.postgresql.org; Mon, 02 Sep 2019 16:42:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i4pP8-00008N-5D for pgsql-jdbc@lists.postgresql.org; Mon, 02 Sep 2019 16:42:10 +0000 Received: from sonic313-13.consmr.mail.bf2.yahoo.com ([74.6.133.123]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i4pP5-0004Hf-5K for pgsql-jdbc@lists.postgresql.org; Mon, 02 Sep 2019 16:42:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1567442525; bh=mF/rR+UgqYZ/i/NEa3Vqc/5sJ0HdWl0C43dH/rz9wIs=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=P003q/0SKIV7oMhlmO0nOzDmcT2aI28a9Da5yDfQugLpEGIcsFPpRwTqQy6j47HIjuyBpVj8ax4nTd/G1L1USLCEftffNY5oLwj08vJvi9BLY7FU4hjPYj+VBGoRAlncTw/OTBoj18PJkX0Zpzi4kWBgr1sS9CfxAZMPXLbVamVQGNDlKfrl2L7lVtTnGaXhsf2qfC2WLUBd3V1tciFjnNqh5qbHgJNDu1r3sF5Mu+Y8H5F/Fj0GmfdsTSki1pvinWGwWvDe5Ra1WnWqz4ehQaPu1CnY5oYmnWRg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ccnG1G4RXIsQ3sfYakVGTyd3UgJTDd1rUqDfiZN mZPlaaPHc_GKL1JRszimFeYgO6IPObDuEQ272mde2dDxPLpvxZflhHTRSOSPO0IxNV9vlv6s8_n7 1FHPLsV.mYD9nMqN4nckGipSr34BY.3wT2jE1IUlQrqo0mecuaLJnOjGXiDqQ7lSiyGMs85DRTbh uSRXSAOJ6gZ8xsD8lP2kVIITew7sF5nxxzMLhA2JEGOQG.ON90DNjqwu5_CVL2LAY7Z8G127CO4a 6srnfgayRCwlKbT2CmC56Lw-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.bf2.yahoo.com with HTTP; Mon, 2 Sep 2019 16:42:05 +0000 Date: Mon, 2 Sep 2019 16:42:02 +0000 (UTC) From: Karen Goh To: pgsql-jdbc@lists.postgresql.org, rob stone Message-ID: <1360229251.839248.1567442522789@mail.yahoo.com> In-Reply-To: <20ca43cc21f85a4d8192b0c552011b3478a256ba.camel@gmail.com> References: <932079842.712590.1567405714491@mail.yahoo.com> <20ca43cc21f85a4d8192b0c552011b3478a256ba.camel@gmail.com> Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next. MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_839247_847754110.1567442522787" Content-Length: 8603 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_839247_847754110.1567442522787 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit I have problem replying at below due to Yahoo's mail limitation. You suggestion doesn't help me in resolving the exception. And there is nothing wrong with the sql as I got the solution from a guy who is an expert in Postgresql. Unfortunately, I can't get him now. The version I am using is 11. And since the code works inside Eclipse, so OS doesn't matter.... Can someone tells me how to resolve the problem? As for the zipcode, it is not a concern whether it is text or whatsoever....because as mentioned all the other data can be printed.... On Monday, September 2, 2019, 3:35:21 PM GMT+8, rob stone wrote: Hello, On Mon, 2019-09-02 at 06:28 +0000, Karen Goh wrote: > Hi experts, > > I have been trying to find a solution in the internet but there is > only 1 solution offered by stackoverflow in which the user uses if it > is not there then use a else to print out there is no more data/row > that appeared in that column. > > Basically, I was trying to get a List which meet certain > search condition so the data will come from 2 tables - one of which > is a column from a join table and the List falls under this > table. > > So, here's the code that I attempt to get the data out but keep > getting ResultSet not positioned properly. > > String[] subjectNames = > request.getParameterValues("txtsubjects"); > String zipcode = > request.getParameter("location"); > List subjList = new > ArrayList(Arrays.asList(subjectNames)); > List myList = new ArrayList<>(); > ArrayList subList = new ArrayList<>(); > CopyOnWriteArrayListnewSub = new > CopyOnWriteArrayList(); > tutor t = new tutor(); > > > String sql1 = "select t.tutor_contact_no, > t.zipcode, t.tutor_id, t2.subject_name FROM s_tutor t > JOIN tutor_subject t2 ON t.tutor_id = t2.tutor_id where t.zipcode = > ? And t2.subject_name = Any((?))"; > > PreparedStatement ps2 = > connection.prepareStatement(sql1); > ps2.setString(1, zipcode); > for (int i = 0; i < subjectNames.length; i++) { > Array array = > connection.createArrayOf("text", subjList.toArray()); > ps2.setArray(2, array); > } > ResultSet rs = ps2.executeQuery(); > while (rs.next()) { > t.setContactNo(rs.getString("tutor_cont > act_no")); > t.setZipcode(rs.getString("zipcode")); > t.settutor_id(rs.getInt("tutor_id")); > > > > for (String s: subjList) > if > (s.contains(rs.getString("subject_name"))) > subjList.add(rs.getString("subject_na > me")); > newSub.addAll(subjList); > } > myList.add(t); > request.setAttribute("tutors", myList); > > request.setAttribute("sub", newSub); > > Please. I hope someone can tell me what's wrong with the code or how > to overcome this error...I have been struggling for 2 weeks already. > > Thanks. > } > myList.add(t); > > request.setAttribute("tutors", myList); > > request.setAttribute("sub", newSub); > > > I'm not an "expert". It is customary on these lists to supply the Postgres version, O/S, JDBC driver version and the JDK version. Also the error message from the PostgreSql log file. Is t.zipcode defined as INTEGER or VARCHAR? I would have used:- AND T2.subject_name = ANY(string_to_array(?)) supplying a suitably constructed string as the second parameter. You also need to cater for the query returning no rows. Hi Robert, Ca HTH, Robert ------=_Part_839247_847754110.1567442522787 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I have problem replying at below due to Yahoo's ma= il limitation.

You suggestion doesn't help me in resolving the e= xception.

And there is nothing wrong with the sql as I got the solut= ion from a guy who is an expert in Postgresql. Unfortunately, I can't = get him now.

The version I am using is 11.

And since the code= works inside Eclipse, so OS doesn't matter....

Can someone tell= s me how to resolve the problem?

As for the zipcode, it is not a co= ncern whether it is text or whatsoever....because as mentioned all the othe= r data can be printed....


On Monday, September 2, 2019, 3:35:21 = PM GMT+8, rob stone <floriparob@gmail.com> wrote:


Hello,
On Mon, 2019-09-02 at 06:28 +0000, Karen Goh wrote:
> Hi expert= s,
>
> I have been trying to find a solution in the internet bu= t there is
> only 1 solution offered by stackoverflow in which the us= er uses if it
> is not there then use a else to print out there is no= more data/row
> that appeared in that column.
>
> Basica= lly, I was trying to get a List<String> which meet certain
> se= arch condition so the data will come from 2 tables - one of which
> i= s a column from a join table and the List<String> falls under this> table.
>
> So, here's the code that I attempt to get = the data out but keep
> getting ResultSet not positioned properly.>
> String[] subjectNames =3D
> request.getParameterVal= ues("txtsubjects");
> String zipcode =3D
>= ; request.getParameter("location");
> List<S= tring> subjList =3D new
> ArrayList<String>(Arrays.asList(su= bjectNames));
> List<tutor> myList =3D n= ew ArrayList<>();
> ArrayList<String> subList= =3D new ArrayList<>();
> CopyOnWriteArrayList<S= tring>newSub =3D new
> CopyOnWriteArrayList<String>();
&g= t; tutor t =3D new tutor();
>
>
>= String sql1 =3D "select t.tutor_contact_no,
> t.zip= code, t.tutor_id, t2.subject_name FROM s_tutor t
> JOIN tutor_subjec= t t2 ON t.tutor_id =3D t2.tutor_id where t.zipcode =3D
> ? And t2.= subject_name =3D Any((?))";
>
> Pr= eparedStatement ps2 =3D
> connection.prepareStatement(sql1);
> = ps2.setString(1, zipcode);
> for (int i =3D 0= ; i < subjectNames.length; i++) {
> Array array = =3D
> connection.createArrayOf("text", subjList.toArray());=
> ps2.setArray(2, array);
> }
&= gt; ResultSet rs =3D ps2.executeQuery();
> wh= ile (rs.next()) {
> t.setContactNo(rs.getStrin= g("tutor_cont
> act_no"));
> = t.setZipcode(rs.getString("zipcode"));
> = t.settutor_id(rs.getInt("tutor_id"));
>
>=
>
> for (String s: subjList)
= > if
> (s.contains(rs.getString("subject_= name")))
> subjList.add(rs.getString("= ;subject_na
> me"));
> newSub.addAll(s= ubjList);
> }
> myList.add(t);
> = request.setAttribute("tutors", myList);
> =
> request.setAttribute("sub"= ;, newSub);
>
> Please. I hope someone can tell me what'= ;s wrong with the code or how
> to overcome this error...I have been = struggling for 2 weeks already.
>
> Thanks.
> = }
> myList.add(t);
>
>= ; request.setAttribute("tutors", myList);
>=
> request.setAttribute("s= ub", newSub);

>
>
>


I'm not an &q= uot;expert".

It is customary on these lists to supply the Postg= res version, O/S,
JDBC driver version and the JDK version.
Also the e= rror message from the PostgreSql log file.

Is t.zipcode defined as I= NTEGER or VARCHAR?

I would have used:-

AND T2.subject_name = =3D ANY(string_to_array(?))

supplying a suitably constructed string = as the second parameter.

You also need to cater for the query return= ing no rows.

Hi Robert,

Ca

HTH,
Robert


<= br>
=20 ------=_Part_839247_847754110.1567442522787--