pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Karen Goh <karenworld@yahoo.com>
To: pgsql-jdbc@lists.postgresql.org, rob stone <floriparob@gmail.com>
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
Date: Mon, 2 Sep 2019 16:42:02 +0000 (UTC)
Message-ID: <1360229251.839248.1567442522789@mail.yahoo.com> (raw)
In-Reply-To: <20ca43cc21f85a4d8192b0c552011b3478a256ba.camel@gmail.com>
References: <932079842.712590.1567405714491@mail.yahoo.com>
	<20ca43cc21f85a4d8192b0c552011b3478a256ba.camel@gmail.com>

 I have problem replying at below due to Yahoo's mail limitation.

You suggestion doesn't help me in resolving the exception.

And there is nothing wrong with the sql as I got the solution from a guy who is an expert in Postgresql. Unfortunately, I can't get him now.

The version I am using is 11.

And since the code works inside Eclipse, so OS doesn't matter....

Can someone tells me how to resolve the problem? 

As for the zipcode, it is not a concern whether it is text or whatsoever....because as mentioned all the other data can be printed....


On Monday, September 2, 2019, 3:35:21 PM GMT+8, rob stone <floriparob@gmail.com> wrote:


Hello,

On Mon, 2019-09-02 at 06:28 +0000, Karen Goh 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_cont
> act_no")); 
> t.setZipcode(rs.getString("zipcode"));
> t.settutor_id(rs.getInt("tutor_id")); 
> 
>
> 
> for (String s: subjList)
> if
> (s.contains(rs.getString("subject_name")))
> subjList.add(rs.getString("subject_na
> me"));
> 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);

>
>
>


I'm not an "expert".

It is customary on these lists to supply the Postgres version, O/S,
JDBC driver version and the JDK version.
Also the error message from the PostgreSql log file.

Is t.zipcode defined as INTEGER or VARCHAR?

I would have used:-

AND T2.subject_name = ANY(string_to_array(?))

supplying a suitably constructed string as the second parameter.

You also need to cater for the query returning no rows.

Hi Robert,

Ca

HTH,
Robert



  

view thread (21+ messages)  latest in thread

Message-ID: <1360229251.839248.1567442522789@mail.yahoo.com>
Permalink:  ../1360229251.839248.1567442522789@mail.yahoo.com/
Also on:    postgresql.org/message-id/1360229251.839248.1567442522789@mail.yahoo.com

 · 

reply

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, floriparob@gmail.com
  Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
  In-Reply-To: <1360229251.839248.1567442522789@mail.yahoo.com>
  References: <932079842.712590.1567405714491@mail.yahoo.com> <20ca43cc21f85a4d8192b0c552011b3478a256ba.camel@gmail.com> <1360229251.839248.1567442522789@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