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 1i519u-0000s5-Jk for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 Sep 2019 05:15:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i519t-0001Lw-GL for pgsql-jdbc@arkaria.postgresql.org; Tue, 03 Sep 2019 05:15:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i519t-0001DT-2G for pgsql-jdbc@lists.postgresql.org; Tue, 03 Sep 2019 05:15:13 +0000 Received: from sonic310-15.consmr.mail.bf2.yahoo.com ([74.6.135.125]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i519q-0000ZR-7b for pgsql-jdbc@lists.postgresql.org; Tue, 03 Sep 2019 05:15:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1567487707; bh=/8P6/AqMSpWCVJ4kx1HB8a5TRgF1Cd208Er6nHkTLGU=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=fQ7LfriOkr45wKvZRmRIJACJzs5VXnEn9ymVTxDTFASZH74xIswPtRrwRiEpP4ugHRNKcF85orePc2UqGaFq3DRHVMhBqWt2sACK1aCEF1Golw56HJnCcLsLGxrbT/HhDT7T7SjGdDT38gYvdT4AkDpvHyrnmxPxMnOXGHnxsZOTDCxr7AUUmoQXWL/JLLA9FHgDj5+dX1BBWj2LCtH4BtjZ0sYgxBqqNldmtzMXLJthZEvqULHZWo/cphTQoUw1oARfrJUjGHp/eqs00FyOjhmg4QIrcNwPUyU1MqoK1bIk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TK6lBymS5jCzG.iLvg3Ah Zi2SLWvUBCP_qKevGo88pKFFQL9OQm4BybpOoFLGawu_OFjXdsS5pW5VmxXb0sNgCpxCq28cDO7r AtoRrQ_MSwQJjFgvvhIYqysLOCiVL9ehCXUqiR.W5gYKa6TITbYfM7YdJlIVTAKC6U8UvEp3NpAo IUKe5zfIy6.0zdvQiYGu0yFVS_TppeKRvxTp36x3uNnWhRaI_c4mPDTs8vMqZzMglbUEqHJXCxud 5e.PQFS7TzA6.4NwzwkU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.bf2.yahoo.com with HTTP; Tue, 3 Sep 2019 05:15:07 +0000 Date: Tue, 3 Sep 2019 05:15:05 +0000 (UTC) From: Karen Goh To: Rob Sargent Cc: pgsql-jdbc@lists.postgresql.org Message-ID: <1422030722.958511.1567487705474@mail.yahoo.com> In-Reply-To: <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com> References: <932079842.712590.1567405714491@mail.yahoo.com> <58285538-686D-45F6-B5A5-883DBE7D0C10@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_958510_736614210.1567487705473" Content-Length: 7145 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_958510_736614210.1567487705473 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =20 Hi Rob, I am still getting the same type of error even if I store it in another Lis= t...=20 CopyOnWriteArrayList subList =3D new CopyOnWriteArrayList<>();=20 subList.add(rs.getString("subject_name")); // note: using a new List Are there anybody experienced Java developer that can help ? On Tuesday, September 3, 2019, 9:12:34 AM GMT+8, Rob Sargent wrote: > On Sep 2, 2019, at 12:28 AM, 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 ther= e then use a else to print out there is no more data/row that appeared in t= hat column. > > Basically, I was trying to get a List which meet certain search c= ondition so the data will come from 2 tables - one of which is a column fro= m 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 R= esultSet not positioned properly. > > String[] subjectNames =3D request.getParameterValues("txtsubjects"); > String zipcode =3D request.getParameter("location"); > List subjList =3D new ArrayList(Arrays.asList(subjectName= s));=20 > List myList =3D new ArrayList<>(); > ArrayList subList =3D new ArrayList<>(); > CopyOnWriteArrayListnewSub =3D new CopyOnWriteArrayList()= ; > tutor t =3D new tutor(); > >=20 > String sql1 =3D "select t.tutor_contact_no, t.zipcode, t.tutor_id, t2.sub= ject_name FROM s_tutor t JOIN tutor_subject t2 ON t.tutor_id =3D t2.tutor_i= d where t.zipcode =3D ? And t2.subject_name =3D Any((?))"; >=20 > PreparedStatement 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); > } > ResultSet rs =3D ps2.executeQuery(); > while (rs.next()) {=20 > t.setContactNo(rs.getString("tutor_contact_no"));=20 > t.setZipcode(rs.getString("zipcode")); > t.settutor_id(rs.getInt("tutor_id"));=20 > >=20 > for (String s: subjList) > if (s.contains(rs.getString("subject_name"))) Are you sure you want to add to the subList you=E2=80=99re iterating throug= h? > subjList.add(rs.getString("subject_name")); > newSub.addAll(subjList); > } > myList.add(t);=20 > request.setAttribute("tutors", myList);=20 > request.setAttribute("sub", newSub);=20 > > Please. I hope someone can tell me what's wrong with the code or how to o= vercome this error...I have been struggling for 2 weeks already. > > Thanks. > } > myList.add(t);=20 > request.setAttribute("tutors", myList);=20 > request.setAttribute("sub", newSub); > > > =20 ------=_Part_958510_736614210.1567487705473 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


Hi Rob,

I am still getting the same typ= e of error even if I store it in another List...

CopyOnWriteArrayLi= st<String> subList =3D new CopyOnWriteArrayList<>();

s= ubList.add(rs.getString("subject_name")); // note: using a new Li= st

Are there anybody experienced Java developer that can help ?
<= br>
On Tuesday, September 3, 2019, 9:12:34 AM GMT+8, Rob Sargent <rob= jsargent@gmail.com> wrote:




> On Sep 2, 2019, at 12= :28 AM, Karen Goh <karenworld@yahoo.com> wrote:
>
> Hi ex= perts,
>
> I have been trying to find a solution in the interne= t but there is only 1 solution offered by stackoverflow in which the user u= ses if it is not there then use a else to print out there is no more data/r= ow that appeared in that column.
>
> Basically, I was trying to= get a List<String> which meet certain search condition so the data w= ill come from 2 tables - one of which is 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.= getParameterValues("txtsubjects");
> String zip= code =3D request.getParameter("location");
> Li= st<String> subjList =3D new ArrayList<String>(Arrays.asList(sub= jectNames));
> List<tutor> myList =3D ne= w ArrayList<>();
> ArrayList<String> subList = =3D new ArrayList<>();
> CopyOnWriteArrayList<St= ring>newSub =3D new CopyOnWriteArrayList<String>();
> = tutor t =3D new tutor();
>
>
> = String sql1 =3D "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 =3D t= 2.tutor_id where t.zipcode =3D ? And t2.subject_name =3D Any((?))";<= br>>
> PreparedStatement ps2 =3D connectio= n.prepareStatement(sql1);
> ps2.setString(1, zipcode);> for (int i =3D 0; i < subjectNames.length; i++) {
&= gt; Array array =3D connection.createArrayOf("text&quo= t;, subjList.toArray());
> ps2.setArray(2, array);> }
> ResultSet rs =3D ps2.executeQuery()= ;
> while (rs.next()) {
> t.= setContactNo(rs.getString("tutor_contact_no"));
>= ; t.setZipcode(rs.getString("zipcode"));
> = t.settutor_id(rs.getInt("tutor_id")); <= br>>
>
> for (String s: subjLi= st)
> if (s.contains(rs.getString("subject_n= ame")))

Are you sure you want to add to the subList you=E2=80= =99re iterating through?

> subjList.add(rs.= getString("subject_name"));
> newSub.ad= dAll(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);
> r= equest.setAttribute("tutors", myList);
&g= t; request.setAttribute("sub", newSub);
>>
>


=20 ------=_Part_958510_736614210.1567487705473--