From: Karen Goh <karenworld@yahoo.com>
To: Rob Sargent <robjsargent@gmail.com>
Cc: pgsql-jdbc@lists.postgresql.org
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
Date: Tue, 3 Sep 2019 05:15:05 +0000 (UTC)
Message-ID: <1422030722.958511.1567487705474@mail.yahoo.com> (raw)
In-Reply-To: <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com>
References: <932079842.712590.1567405714491@mail.yahoo.com>
<58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com>
Hi Rob,
I am still getting the same type of error even if I store it in another List...
CopyOnWriteArrayList<String> subList = new CopyOnWriteArrayList<>();
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 <robjsargent@gmail.com> wrote:
> On Sep 2, 2019, at 12:28 AM, Karen Goh <karenworld@yahoo.com> 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 there then use a else to print out there is no more data/row that appeared in that column.
>
> Basically, I was trying to get a List<String> which meet certain search condition so the data will 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 = 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 s: subjList)
> if (s.contains(rs.getString("subject_name")))
Are you sure you want to add to the subList you’re iterating through?
> subjList.add(rs.getString("subject_name"));
> newSub.addAll(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);
> request.setAttribute("tutors", myList);
> request.setAttribute("sub", newSub);
>
>
>
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: karenworld@yahoo.com, robjsargent@gmail.com
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
In-Reply-To: <1422030722.958511.1567487705474@mail.yahoo.com>
References: <932079842.712590.1567405714491@mail.yahoo.com> <58285538-686D-45F6-B5A5-883DBE7D0C10@gmail.com> <1422030722.958511.1567487705474@mail.yahoo.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