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 1i6RJb-0005el-9K for pgsql-jdbc@arkaria.postgresql.org; Sat, 07 Sep 2019 03:23:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i6RIb-0005C7-Aq for pgsql-jdbc@arkaria.postgresql.org; Sat, 07 Sep 2019 03:22:05 +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 1i6RIa-0004vG-Az for pgsql-jdbc@lists.postgresql.org; Sat, 07 Sep 2019 03:22:05 +0000 Received: from sonic315-15.consmr.mail.bf2.yahoo.com ([74.6.134.125]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i6RIS-00042n-Lx for pgsql-jdbc@lists.postgresql.org; Sat, 07 Sep 2019 03:22:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1567826515; bh=lrLhIIwOLFx2wGCY8U6l0S4DpnR0UUne1rvPGLA+Eu0=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=XunsvJJoQjQZmzfjd5f5OsVtAKNY/5xfdJXiIAO+tjWogTQfe5fSJhablZz07L8vViS0LxPSNe6z7hAvRtcRa29VR1GQO3qUauOCbUVTWt7rFerxfTPNJSDC4pziHsR+fzNCJRncd+2UyluEl7ndnUu428HUq+pwed5gV3e+mDHHA1uIZGshe+yuD/9UT12MJu1mnwOo0DCPO81rGnIeuXWEVEmwpAfCdAsnK4P3yJMM79T9xnvtWlrDflTitPNKOtbfvA8EEE1ee3Uzr0hs7fgXkWH0o0J+Zfav5Qx9j4QO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c02sJr6OTx8HY3tzNTU2WViQbvUqnDwRStMZ ca4f4w0SUhPM_15TTLsCEZajf5Tg0CNp95u3hlzJ_vZCAIJZdabp1z6qIWXXJMzcNH_CvHT8.qea u2jV0e_f5rJyn9EKP8DB7WF8aCmGXxYmLGYEgVgYpt3VbwEMqX6oarcWd4.ASsFMe9X9sIaWjX1_ e09oP9Fwy4yRgzdxm8af1VIEAWQNpFblXgrY4NzCoJ5SRdD965GJf92auyjCTaqsSwXaN9TuDbXV 7NNpGXGCfStqmrU3AN5DKCJHtwLbi1BenddpktFi9zrH95xQwKWZJ0xkC Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.bf2.yahoo.com with HTTP; Sat, 7 Sep 2019 03:21:55 +0000 Date: Sat, 7 Sep 2019 03:21:51 +0000 (UTC) From: Karen Goh To: Rob Sargent Cc: pgsql-jdbc@lists.postgresql.org Message-ID: <440942117.2418399.1567826511126@mail.yahoo.com> In-Reply-To: References: <932079842.712590.1567405714491@mail.yahoo.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_2418398_169581378.1567826511119" Content-Length: 74879 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_2418398_169581378.1567826511119 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Rob, I found out that Tomcat is inconsistent in giving me the result and as ment= ioned, even though certain lines are commented out it is pointing to the co= mmented out lines. And even after clearing cache whatsoever, I am still getting the old error = which is not supposed to be there. Till I really iron out all Tomcat problem, I can't comment anything. But, a= s of now, the problem I posted here is dissolved. Right now, it is giving me concurrentModificationList exception at (String = s : subject) but this is Java problem and nothing to do with Postgresql...s= o that's the state of thing now. Thanks for the reply thought....oh the list is part of the domain model....= .as what you have to do to every Model construction... On Friday, September 6, 2019, 3:24:42 PM GMT+8, Rob Sargent wrote: =20 =20 =20 On Sep 2, 2019, at 12:28 AM, Karen Goh wrote: String[] subjectNames =3D request.getParameterValues("txtsubjects"); String zipcode =3D request.getParameter("location"); List subjList =3D new ArrayList(Arrays.asList(subjectNam= es)); =20 List myList =3D new ArrayList<>(); ArrayList subList =3D new ArrayList<>(); CopyOnWriteArrayListnewSub =3D new CopyOnWriteArrayList(= );=C2=A0 tutor t =3D new tutor(); =20 String sql1 =3D "select t.tutor_contact_no, t.zipcode, t.tutor_id, t2.su= bject_name FROM s_tutor t JOIN tutor_subject t2 =C2=A0ON t.tutor_id =3D t2.= tutor_id where t.zipcode =3D ? =C2=A0And =C2=A0t2.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 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0for (String s: subjList) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (s.contains(rs.getStr= ing("subject_name"))) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0subjList.add= (rs.getString("subject_name")); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 newSub.addAll(subjList); } myList.add(t); =20 request.setAttribute("tutors", myList); =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 request.setAttribute("sub", newSub);=20 Please. =C2=A0I 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); =20 request.setAttribute("tutors", myList); =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 request.setAttribute("sub", newSub); I put your code into my editor as if it were an entire method. =C2=A0That f= ormatted version is below.I find the for loop very odd. See comments with y= our code below, in bold for easy reference: void func() {// subjectNames set from the request=C2=A0 =C2=A0 String[] sub= jectNames =3D request.getParameterValues("txtsubjects");=C2=A0 =C2=A0 Strin= g zipcode =3D request.getParameter("location=E2=80=9D);// subjList built fr= om subjectNames=C2=A0 =C2=A0 List subjList =3D new ArrayList(Arrays.asList(subjectNames)); =C2=A0 =C2=A0 List myList =3D new Ar= rayList<>();=C2=A0 =C2=A0 ArrayList subList =3D new ArrayList<>();= =C2=A0 =C2=A0 CopyOnWriteArrayListnewSub =3D new CopyOnWriteArrayLi= st();=C2=A0=C2=A0 =C2=A0 tutor t =3D new tutor(); =C2=A0 =C2=A0 String sql1 =3D "select t.tutor_contact_no, t.zipcode, t.tut= or_id, t2.subject_name FROM s_tutor t JOIN tutor_subject t2 =C2=A0ON t.tuto= r_id =3D t2.tutor_id where t.zipcode =3D ? =C2=A0And =C2=A0t2.subject_name = =3D Any((?))"; =C2=A0 =C2=A0 PreparedStatement ps2 =3D connection.prepareSt= atement(sql1);=C2=A0 =C2=A0 ps2.setString(1, zipcode);=C2=A0 =C2=A0 for (in= t i =3D 0; i < subjectNames.length; i++) {// subjList add to query=C2=A0 = =C2=A0 =C2=A0 =C2=A0 Array array =3D connection.createArrayOf("text", subjL= ist.toArray());=C2=A0 =C2=A0 =C2=A0 =C2=A0 ps2.setArray(2, array);=C2=A0 = =C2=A0 }=C2=A0 =C2=A0 ResultSet rs =3D ps2.executeQuery();=C2=A0 =C2=A0 whi= le (rs.next()) { =C2=A0 =C2=A0 =C2=A0 =C2=A0 t.setContactNo(rs.getString("t= utor_contact_no")); =C2=A0 =C2=A0 =C2=A0 =C2=A0 t.setZipcode(rs.getString("= zipcode"));=C2=A0 =C2=A0 =C2=A0 =C2=A0 t.settutor_id(rs.getInt("tutor_id"))= ;=20 =C2=A0=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 for (String s: subjList)// test i= f one entry of subjList matches the current row=E2=80=99s =E2=80=9Csubject_= name=E2=80=9D value,=C2=A0// repeatedly asking for=C2=A0=E2=80=9Csubject_na= me=E2=80=9D from current rs=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (s.= contains(rs.getString("subject_name")))// if so add current value to list b= eing iterated=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 subjLi= st.add(rs.getString("subject_name"));=C2=A0 =C2=A0 =C2=A0 =C2=A0 newSub.add= All(subjList);// If I follow the intent correctly (match subjects to tutor)= I believe the following would be more effective=C2=A0 =C2=A0 =C2=A0 =C2=A0= String rsSubject =3D rs.getString("subject_name");=C2=A0 =C2=A0 =C2=A0 =C2= =A0 if (subjList.contains(rsSubject)) {=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 newSub.add(rsSubject);=C2=A0 =C2=A0 =C2=A0 =C2=A0 }// However your s= ql seems to be asking for all tutors in a given zipcode and what subjects t= hey handle. =C2=A0You might want to at least order the return set by tutor = to deal with one tutor over several result rows. =C2=A0Alternatively you co= uld group subjects into an array per tutor:String sql1 =3D "select t.tutor_= contact_no, t.zipcode, t.tutor_id, array_agg(t2.subject_name) FROM s_tutor = t JOIN tutor_subject t2 =C2=A0ON t.tutor_id =3D t2.tutor_id where t.zipcode= =3D ? =C2=A0And =C2=A0t2.subject_name =3D Any((?)) group by t.tutor_contac= t_no,t.zipcode,t.tutor_id=E2=80=9D;and grab the array of tutor=E2=80=99s su= bjects.Further your responce doesn=E2=80=99t tie specific tutor to specific= subjects. =C2=A0Perhaps you can add Listsubjects to your=C2=A0=E2= =80=9Ctutor=E2=80=9D class? =C2=A0 =C2=A0 }=C2=A0 =C2=A0 myList.add(t); =C2=A0 =C2=A0 request.setAttrib= ute("tutors", myList); =C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 request.set= Attribute("sub", newSub); } I hope this helps. =20 ------=_Part_2418398_169581378.1567826511119 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Rob,

I found out that Tomcat is inconsistent= in giving me the result and as mentioned, even though certain lines are co= mmented out it is pointing to the commented out lines.

And even afte= r clearing cache whatsoever, I am still getting the old error which is not = supposed to be there.

Till I really iron out all Tomcat problem, I c= an't comment anything. But, as of now, the problem I posted here is di= ssolved.

Right now, it is giving me concurrentModificationList excep= tion at (String s : subject) but this is Java problem and nothing to do wit= h Postgresql...so that's the state of thing now.

Thanks for the = reply thought....oh the list is part of the domain model.....as what you ha= ve to do to every Model construction...
On Frida= y, September 6, 2019, 3:24:42 PM GMT+8, Rob Sargent <robjsargent@gmail.c= om> wrote:

=

<= br class=3D"yiv7459822408" clear=3D"none">

On Sep 2, 2019, at 12:28 AM, Karen Goh <karenworl= d@yahoo.com> wrote:

= =09String[] subjectNa= mes =3D request.getParameterValues("txtsubjects");
=09=09=09Strin= g zipcode =3D request.getParameter("location");
=09=09=09List<= String> subjList =3D new ArrayList<String>(Arrays.asList(subjectNa= mes));=09=09= =09
= =09=09=09List<tutor> myList =3D ne= w ArrayList<>();
= =09=09=09ArrayList<String> subList= =3D new ArrayList<>();
=09=09=09CopyOnWriteArrayList<St= ring>newSub =3D new CopyOnWriteArrayList<String>(); 
=09=09=09tutor = t =3D new tutor();

=09
=09=09
=09=09=09String sql1 =3D "select t.tutor_contact_no, t.= zipcode, t.tutor_id, t2.subject_name FROM s_tutor t JOIN tutor_subject t2 &= nbsp;ON t.tutor_id =3D t2.tutor_id where t.zipcode =3D ?  And  t2= .subject_name =3D Any((?))";
=09=09=09
=09=09=09PreparedStatement ps2 =3D connection.prepareStatement(sql1)= ;
=09=09=09ps2.setString(1, zipcode);
=09=09=09for (i= nt i =3D 0; i < subjectNames.length; i++) {
=09=09=09=09Array array =3D connection.createArrayOf("text", sub= jList.toArray());
=09
=09=09=09ps2.set= Array(2, array);
=09=09=09}
=09=09= =09ResultSet rs =3D p= s2.executeQuery();
=09=09=09while (rs.next()) {=09=09
<= span class=3D"yiv7459822408Apple-tab-span" style=3D"font-family:CourierNewP= SMT;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:norm= al;text-indent:0px;text-transform:none;white-space:pre;word-spacing:0px;tex= t-decoration:none;">=09
=09=09=09t.setContactNo(rs.getString("tutor_contact_no"));=09=09=09
=09<= span class=3D"yiv7459822408Apple-tab-span" style=3D"font-family:CourierNewP= SMT;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:norm= al;text-indent:0px;text-transform:none;white-space:pre;word-spacing:0px;tex= t-decoration:none;">=09
=09=09t.setZipcod= e(rs.getString("zipcode"));
=09=09=09= =09t.settutor_id(rs.getInt("tutor_id"));=09
=09=09

=09=09=09   
=09=09=09    for (String s: sub= jList)
=09=09=09        if (s.contains(rs.= getString("subject_name")))
=09=09=09=        &nb= sp;  subjList.add(rs.getString("subject_name"));
=09=09=09  &= nbsp;  =09newSub.addAll(subjList);
}
myList.add(t);= =09=09=09=09=09
=09=09=09= =09request.setAttribu= te("tutors", myList);=09=09=09=09       <= /span>
=09=09=09=09request.setAttribute("sub= ", newSub);=09
Please. =  I hope someone can tell me what's wrong with the code or how to overc= ome this error...I have been struggling for 2 weeks already.

Thanks.
=09=09=09}
=09
=09=09=09myList.add(t);=09=09=09=09=09
=09=09= =09=09request.setAttribute("tutors", myList);=09=09=09=09  =      
=09=09=09=09request.setAttribute("sub", newSub);
<= br class=3D"yiv7459822408" clear=3D"none">
I pu= t your code into my editor as if it were an entire method.  That forma= tted version is below.
I find the for loo= p very odd. See comments with your code below, in bold for easy reference:<= /div>

void func= () {
// subjec= tNames set from the request
  &n= bsp; String[] subjectNames =3D request.getParameterValues("txtsubjects");
    String zipcode =3D request.g= etParameter("location=E2=80=9D);
// subjList built from subjectNames
    List<String> subjList =3D new ArrayL= ist<String>(Arrays.asList(subjectNames));=09=09=09
    List<tutor> myList =3D new ArrayList= <>();
    ArrayList<St= ring> subList =3D new ArrayList<>();
    CopyOnWriteArrayList<String>newSub =3D new CopyOnW= riteArrayList<String>(); 
&nbs= p;   tutor t =3D new tutor();

=09=09= =09
    String sql1 =3D = "select t.tutor_contact_no, t.zipcode, t.tutor_id, t2.subject_name FROM s_t= utor t JOIN tutor_subject t2  ON t.tutor_id =3D t2.tutor_id where t.zi= pcode =3D ?  And  t2.subject_name =3D Any((?))";
=09=09=09
  &n= bsp; PreparedStatement ps2 =3D connection.prepareStatement(sql1);
    ps2.setString(1, zipcode);
    for (int i =3D 0; i < subjectName= s.length; i++) {
// subjList add to query
  &n= bsp;     Array array =3D connection.createArrayOf("text", subjLis= t.toArray());
       = ps2.setArray(2, array);
    }<= /div>
    ResultSet rs =3D ps2.execut= eQuery();
    while (rs.next())= {= =09=09
       = t.setContactNo(rs.getString("tutor_contact_no"));=09=09=09
        t.setZipcode(rs.getString= ("zipcode"));
       = t.settutor_id(rs.getInt("tutor_id"));=09=09=09

=09=09=09   
&n= bsp;       for (String s: subjList)
// test if one entry of subjList match= es the current row=E2=80=99s =E2=80=9Csubject_name=E2=80=9D value, 
// repeatedl= y asking for =E2=80=9Csubject_name=E2=80=9D from current rs
<= div class=3D"yiv7459822408">            if (s= .contains(rs.getString("subject_name")))
= // if so add current value to list being iterate= d
          =       subjList.add(rs.getString("subject_name"));
        newSub.addAll(subjList)= ;
// If I foll= ow the intent correctly (match subjects to tutor) I believe the following w= ould be more effective
        Strin= g rsSubject =3D rs.getString("subject_name");
        if (subjLis= t.contains(rsSubject)) {
            newSub.add(rsSubje= ct);
 = ;       }
// However your sql seems to be asking for all tutors = in a given zipcode and what subjects they handle.  You might want to a= t least order the return set by tutor to deal with one tutor over several r= esult rows.  
Alternatively you could group subjects into an array per tutor:
String sql1 = =3D "select t.tutor_contact_no, t.zipcode, t.tutor_id, array_agg(t2.subject= _name) FROM s_tutor t JOIN tutor_subject t2  ON t.tutor_id =3D t2.tuto= r_id where t.zipcode =3D ?  And  t2.subject_name =3D Any((?)) gro= up by t.tutor_contact_no,t.zipcode,t.tutor_id=E2=80=9D;
and grab the array of tutor= =E2=80=99s subjects.
Further your responce doesn=E2=80=99t tie specific tutor to spec= ific subjects.  Perhaps you can add List<String>subjects to your=  =E2=80=9Ctutor=E2=80=9D class?


=
    }
    myList.add(t);=09=09=09=09=09
    request.setAttribute("tutors", myList);=09=09=09= =09       
    request.setAttribute("sub", newSub);
=09
}

I hope= this helps.
------=_Part_2418398_169581378.1567826511119--