Re: how to resolve org.postgresql.util.PSQLException: ResultSet notpositioned properly, perhaps you need to call next. - Mailing list pgsql-jdbc

From Karen Goh
Subject Re: how to resolve org.postgresql.util.PSQLException: ResultSet notpositioned properly, perhaps you need to call next.
Date
Msg-id 860006402.1322813.1567568281784@mail.yahoo.com
Whole thread Raw
In response to Re: how to resolve org.postgresql.util.PSQLException: ResultSet notpositioned properly, perhaps you need to call next.  (Rob Sargent <robjsargent@gmail.com>)
Responses Re: how to resolve org.postgresql.util.PSQLException: ResultSet notpositioned properly, perhaps you need to call next.  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-jdbc
Sure.
I tried various ways to see if there is any mistakes. Still, I get the same old error :(

Very difficult to type in Yahoo mail now...so I am continuing here (after you read the last sentence of the mail)

So, even if I remove the System.out.print...it still gives me the error...

Could it be Tomcat problem ? because I remove the page forwarded lines all altogether and it gave me the same old error as per not positioned properly, blah ...

org.postgresql.util.PSQLException: ResultSet not positioned properly, perhaps you need to call next.
at org.postgresql.jdbc.PgResultSet.checkResultSet(PgResultSet.java:2772)
at org.postgresql.jdbc.PgResultSet.getInt(PgResultSet.java:2052)
at org.postgresql.jdbc.PgResultSet.getInt(PgResultSet.java:2485)
at Controller.searchController.doPost(searchController.java:117)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

And below the line that is giving problem :
subjList.add(rs.getString("subject_name"));
newSub.addAll(subjList);

System.out.println( "tutor ID=" + rs.getInt("tutor_id") + "zipcode =" + rs.getString("zipcode") +
"subjectName=" + rs.getString("subject_name") + "tutorContact=" +
rs.getString("tutor_contact_no"));
}}
I now inserted it before the close bracket of resultset.

It points to System.out.print





On Wednesday, September 4, 2019, 3:23:46 AM GMT+8, Rob Sargent <robjsargent@gmail.com> wrote:


Well we’ll need to see the stacktrace from the exception and proof (line numbers) that the exception is in the code you sent.


> On Sep 2, 2019, at 11:15 PM, Karen Goh <karenworld@yahoo.com> wrote:
>
>
>
> 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);
> >
> >
> >
>
>


pgsql-jdbc by date:

Previous
From: Pavel Raiskup
Date:
Subject: [pgjdbc/pgjdbc] 849512: rpm: remove karaf plugin
Next
From: Rob Sargent
Date:
Subject: Re: how to resolve org.postgresql.util.PSQLException: ResultSet notpositioned properly, perhaps you need to call next.