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 1i6Tya-0002U2-4q for pgsql-jdbc@arkaria.postgresql.org; Sat, 07 Sep 2019 06:13:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i6TyX-0006v5-F0 for pgsql-jdbc@arkaria.postgresql.org; Sat, 07 Sep 2019 06:13:33 +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 1i6TyX-0006rz-3u for pgsql-jdbc@lists.postgresql.org; Sat, 07 Sep 2019 06:13:33 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i6TyQ-0007NX-FS for pgsql-jdbc@lists.postgresql.org; Sat, 07 Sep 2019 06:13:32 +0000 Received: by mail-qt1-x843.google.com with SMTP id o12so9933021qtf.3 for ; Fri, 06 Sep 2019 23:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=uzmYV5QXFXRZHeU8iBadROUt+a7uWTol98t9PjX5rYk=; b=K+ZflXRhPAqjI97wbhiy/QDzjIN+VjDokvhHCkaKYKs9nH6Q+qN3MvV+wADGQOgYzR lMnTXuDDqVle7286Rla8inU4M1a1JTKsOZCt7nJv1HxlHEBeO/Eyg3CqY+l2qK7cxFkD WXfqU6ofhvz6BFWelkvnS5yTKLkvFWzWXVmWQEA8mtn4PWJjBelTeQ9tMrnj3Pu84ruJ DnRWR+jzKgLAwGogY+rCRYUZYVRbJG+hEWm+t6EMm1ashS1HJapu9St62R21ZQvo+ea+ Ss0fY2lZSC1HEFK5VKlkwXEWGbs6vP8y2qUV/WMTLoO8lXg/WyIfYDgq0f5P6GZ6DibM 7saQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=uzmYV5QXFXRZHeU8iBadROUt+a7uWTol98t9PjX5rYk=; b=SHsWaDniqXyrStnd8q5uJtjJNzdm4s52VNAiPrPPUPbSL0P+Uj0WBBRamoIG2Lru8p B3XV/b36dr1264dt4rpETFcSG6Z6hUto+u/Y39uHDZojFJy6joFNSn/UkY5LO1uzGLMw l+o91jwqB4GaNm+IrlVdYfZgjratouCTfscitsqawf8Gjjccuu9418HBssiLqNQ09Yxz h9N5fEf9wf11ZoCMB8nNVy155tEe0zrGQAelr0yJfuAJNcA3I+0kUylieVyy6D+q9iNS 0ROvM9jVqUzI4fSrYuoBKb3cb1PShgPeNXs4siRW6VO+mAhKZAM9POXb/YO/3fpdobzJ yriA== X-Gm-Message-State: APjAAAUAVZRSLu8v6t1nrWfmRPOY06zdAk0sq0gcQ4Zpg3AlndtfoU1M X0uCji2RbKQberFOQ3KrXrYcr7SY6H6vhg== X-Google-Smtp-Source: APXvYqynp9gv9gcOElfrV3YzGgXPe/7Btb7P5NLgsUKAPXm62P96VBxx+aMBJbPHOWMBLO87ooGrZw== X-Received: by 2002:a63:6f8f:: with SMTP id k137mr11108236pgc.90.1567835230715; Fri, 06 Sep 2019 22:47:10 -0700 (PDT) Received: from [192.168.1.35] (xplr-208-114-165-80.xplornet.com. [208.114.165.80]) by smtp.gmail.com with ESMTPSA id s76sm6454685pgc.92.2019.09.06.22.47.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Sep 2019 22:47:10 -0700 (PDT) From: Rob Sargent Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_71A93882-7E51-4187-8F91-4C941CA358A7" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next. Date: Fri, 6 Sep 2019 23:46:52 -0600 In-Reply-To: <440942117.2418399.1567826511126@mail.yahoo.com> Cc: pgsql-jdbc@lists.postgresql.org To: Karen Goh References: <932079842.712590.1567405714491@mail.yahoo.com> <440942117.2418399.1567826511126@mail.yahoo.com> X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_71A93882-7E51-4187-8F91-4C941CA358A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Sep 6, 2019, at 9:21 PM, Karen Goh wrote: >=20 > Hi Rob, >=20 > I found out that Tomcat is inconsistent in giving me the result and as = mentioned, even though certain lines are commented out it is pointing to = the commented out lines. >=20 > And even after clearing cache whatsoever, I am still getting the old = error which is not supposed to be there. >=20 > Till I really iron out all Tomcat problem, I can't comment anything. = But, as of now, the problem I posted here is dissolved. >=20 > Right now, it is giving me concurrentModificationList exception at = (String s : subject) but this is Java problem and nothing to do with = Postgresql...so that's the state of thing now. Yes, that=E2=80=99s what I suspected in my note about =E2=80=9Ccurrent = list being iterated=E2=80=9D. I think you might be better off with = something similar to my approach to reading the =E2=80=9Csubject_name=E2=80= =9D value only once for each row. Does your query return multiple rows per tutor per execution as I = suspect from reading your query? >=20 > Thanks for the reply thought....oh the list is part of the domain = model.....as what you have to do to every Model construction... > =20 > for (String s: subjList) > // test if one entry of subjList matches the current row=E2=80=99s = =E2=80=9Csubject_name=E2=80=9D value,=20 > // repeatedly asking for =E2=80=9Csubject_name=E2=80=9D from current = rs > if (s.contains(rs.getString("subject_name"))) > // if so add current value to list being iterated > subjList.add(rs.getString("subject_name")); > newSub.addAll(subjList); > // If I follow the intent correctly (match subjects to tutor) I = believe the following would be more effective > String rsSubject =3D rs.getString("subject_name"); > if (subjList.contains(rsSubject)) { > newSub.add(rsSubject); > } > // However your sql seems to be asking for all tutors in a given = zipcode and what subjects they handle. You might want to at least order = the return set by tutor to deal with one tutor over several result rows. = =20 > 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.tutor_id where t.zipcode =3D ? And t2.subject_name =3D= Any((?)) group 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 specific = subjects. Perhaps you can add Listsubjects to your =E2=80=9Ctutor= =E2=80=9D class? >=20 >=20 > } > myList.add(t); =09 > request.setAttribute("tutors", myList); = =20 > request.setAttribute("sub", newSub); > =09 > } >=20 > I hope this helps. --Apple-Mail=_71A93882-7E51-4187-8F91-4C941CA358A7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Sep 6, 2019, at 9:21 PM, Karen Goh <karenworld@yahoo.com> wrote:

= Hi Rob,

I found out that Tomcat = is inconsistent in giving me the result and as mentioned, even though = certain lines are commented out it is pointing to the commented 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, as 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...so that's the state = of thing now.

Yes, that=E2=80=99s what I suspected in my note about = =E2=80=9Ccurrent list being iterated=E2=80=9D.  I think you might = be better off with something similar to my approach to reading the = =E2=80=9Csubject_name=E2=80=9D value only once for each = row.

Does your query return multiple = rows per tutor per execution as I suspect from reading your = query?


Thanks for the reply = thought....oh the list is part of the domain model.....as what you have = to do to every Model construction...
=
=
=
  =  
        for (String s: = subjList)
// = test if one entry of subjList matches the current row=E2=80=99s = =E2=80=9Csubject_name=E2=80=9D value, 
// repeatedly asking = for =E2=80=9Csubject_name=E2=80=9D from current rs
            if = (s.contains(rs.getString("subject_name")))
// if so add current = value to list being iterated
  =               = subjList.add(rs.getString("subject_name"));
        = newSub.addAll(subjList);
// If I follow the intent correctly (match = subjects to tutor) I believe the following would be more = effective
      =   String rsSubject =3D rs.getString("subject_name");
      =   if (subjList.contains(rsSubject)) {
      =       newSub.add(rsSubject);
      =   }
// However your sql seems to be asking for all = tutors in a given zipcode and what subjects they handle.  You might = want to at least order the return set by tutor to deal with one tutor = over several result 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.tutor_id where t.zipcode =3D = ?  And  t2.subject_name =3D Any((?)) group 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 specific subjects.  Perhaps you can add = List<String>subjects to your =E2=80=9Ctutor=E2=80=9D = class?


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

I hope this helps.
=

= --Apple-Mail=_71A93882-7E51-4187-8F91-4C941CA358A7--