From: rob stone <floriparob@gmail.com>
To: Karen Goh <karenworld@yahoo.com>
To: pgsql-jdbc@lists.postgresql.org, Mark Rotteveel <mark@lawinegevaar.nl>
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
Date: Wed, 04 Sep 2019 18:40:46 +1000
Message-ID: <9b008bfa3107e8a3f7505b6f300237d1e13eff7f.camel@gmail.com> (raw)
In-Reply-To: <1705600642.1365952.1567582413285@mail.yahoo.com>
References: <932079842.712590.1567405714491@mail.yahoo.com>
<58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com>
<1422030722.958511.1567487705474@mail.yahoo.com>
<1ACDE5B3-3F0E-4BF0-8C37-DAD09F35F30C@gmail.com>
<860006402.1322813.1567568281784@mail.yahoo.com>
<B3FFC2E6-0BBC-41F5-863B-396417CB0FDF@gmail.com>
<1829430979.1362196.1567576711470@mail.yahoo.com>
<8b79560c-3108-af04-e74f-f4fb55aa0624@lawinegevaar.nl>
<1705600642.1365952.1567582413285@mail.yahoo.com>
Hello,
On Wed, 2019-09-04 at 07:33 +0000, Karen Goh wrote:
> Here's the entire code again:
>
> String[] subjectNames = request.getParameterValues("txtsubjects");
> > > String zipcode = request.getParameter("location");
> > > List<String> subjList = new
> ArrayList<String>(Arrays.asList(subjectNames));
> > > List<tutor> myList = new ArrayList<>();
> > > ArrayList<String> subList = new ArrayList<>();
> > > CopyOnWriteArrayList<String>newSub = new
> CopyOnWriteArrayList<String>();
> > > 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_contact_no"));
> > > t.setZipcode(rs.getString("zipcode"));
> > > t.settutor_id(rs.getInt("tutor_id"));
> > >for (String : subjList)
>
As I said last time, I'm not an "expert".
subjectNames is declared as an array.
In your "for" loop you will be doing ps2.setArray(2, array); multiple
times depending on the number of subjects contained in subjectNames.
I suspect the query is failing and as there is no try .. catch block to
trap the SQLException, this is not reported back to your code.
If you alter the postgresql.conf to log all SQL statements, restart,
run your test again, look in the log file, it will show the passed
parameter values. You can then verify that that the array passed as the
second parameter is correct.
HTH,
Robert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: floriparob@gmail.com, karenworld@yahoo.com, mark@lawinegevaar.nl
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
In-Reply-To: <9b008bfa3107e8a3f7505b6f300237d1e13eff7f.camel@gmail.com>
References: <932079842.712590.1567405714491@mail.yahoo.com> <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com> <1422030722.958511.1567487705474@mail.yahoo.com> <1ACDE5B3-3F0E-4BF0-8C37-DAD09F35F30C@gmail.com> <860006402.1322813.1567568281784@mail.yahoo.com> <B3FFC2E6-0BBC-41F5-863B-396417CB0FDF@gmail.com> <1829430979.1362196.1567576711470@mail.yahoo.com> <8b79560c-3108-af04-e74f-f4fb55aa0624@lawinegevaar.nl> <1705600642.1365952.1567582413285@mail.yahoo.com> <9b008bfa3107e8a3f7505b6f300237d1e13eff7f.camel@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox