Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Karen Goh <karenworld(at)yahoo(dot)com>
Cc: pgsql-jdbc(at)lists(dot)postgresql(dot)org
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
Date: 2019-09-07 05:46:52
Message-ID: D9E5D4FB-E6CD-4050-8535-C8CF9883DE16@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

> On Sep 6, 2019, at 9:21 PM, Karen Goh <karenworld(at)yahoo(dot)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’s what I suspected in my note about “current list being iterated”. I think you might be better off with something similar to my approach to reading the “subject_name” 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’s “subject_name” value,
> // repeatedly asking for “subject_name” 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 = 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 = "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 = t2.tutor_id where t.zipcode = ? And t2.subject_name = Any((?)) group by t.tutor_contact_no,t.zipcode,t.tutor_id”;
> and grab the array of tutor’s subjects.
> Further your responce doesn’t tie specific tutor to specific subjects. Perhaps you can add List<String>subjects to your “tutor” class?
>
>
> }
> myList.add(t);
> request.setAttribute("tutors", myList);
> request.setAttribute("sub", newSub);
>
> }
>
> I hope this helps.

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2019-09-09 13:30:02 [pgjdbc/pgjdbc] cf42ba: [maven-release-plugin] prepare release REL42.2.6
Previous Message Karen Goh 2019-09-07 03:21:51 Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.