Thread: resultset.first() untrappable error
the following code frag has recently started bombing in a bean. It produces no trappable error I can see (SQLException, Exception, RuntimeException all fail) and is bombing at the ResultSet.first() function call. Its using redhat 7.3 postgres jdbc pg73b1jdbcX jars. The db is 7.3.2. jdk is sun hotspot 1.41-b21. The sql works in a file with hard coded customer id. query = "SELECT TO_CHAR(break,'MI9999990D99') as value," + " TO_CHAR(discount,'MI9999990D99') " + " FROM customer " + " WHERE id='" + custid + "'" + " AND discount > 0 " + " UNION " + "SELECT TO_CHAR(value,'MI9999990D99')," + " TO_CHAR(discount,'MI9999990D99') " + " FROM discountbyvalue " + " WHERE account='" + custid + "' " + " ORDER BY value"; results = stmt.executeQuery(query); // only output discounts if there are some */ if( ! results.first() ){ results.close(); stmt.close(); return ""; } Anybody got an idea why?
By "bombing", do you mean no error message at all? What behavior lets you know that it has failed? Especially if the code once worked and wasn't changed when it started failing, we'll need a description of what you're seeing (or not seeing) when it fails. -Nick > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of kevin > Sent: Friday, August 15, 2003 9:12 AM > To: pgsql-jdbc@postgresql.org > Subject: [JDBC] resultset.first() untrappable error > > > the following code frag has recently started bombing in a bean. It > produces no trappable error I can see (SQLException, Exception, > RuntimeException all fail) and is bombing at the ResultSet.first() > function call. Its using redhat 7.3 postgres jdbc pg73b1jdbcX jars. > The db is 7.3.2. jdk is sun > hotspot 1.41-b21. The sql works in a file with hard coded customer id. > > query = "SELECT TO_CHAR(break,'MI9999990D99') as value," + > " TO_CHAR(discount,'MI9999990D99') " + > " FROM customer " + > " WHERE id='" + custid + "'" + > " AND discount > 0 " + > " UNION " + > "SELECT TO_CHAR(value,'MI9999990D99')," + > " TO_CHAR(discount,'MI9999990D99') " + > " FROM discountbyvalue " + > " WHERE account='" + custid + "' " + > " ORDER BY value"; > > results = stmt.executeQuery(query); > > // only output discounts if there are some */ > if( ! results.first() ){ > results.close(); > stmt.close(); > return ""; > } > > Anybody got an idea why? > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html >
bomb. a call has been made to the jsp page defined isErrorPage=true with no valid Exception object. exception==null This only ever happened before when i'd got confused about frame pages and jsp object refs. this code has worked fine as far as i know until the code was ported from 7.1x to 7.3.2. That might be a red herring, but the observable diagnostic is that the tracing begins in my error within error trapping in the jsp error page. the code will jump straight to the error bypassing any code of the form if(rst.first()) { // do something } HTH. Kev
Kevin- Looking at the code fragments, there's nothing obviously wrong, but we're just seeing pieces. Given that nothing is obvious, I'd suggest it is time to just start adding some debug statements to narrow it down... > a call has been made to the jsp page defined isErrorPage=true with no > valid > Exception object. > exception==null So apparently an exception is being thrown, but is invalid by the time it gets passed to the error page. Perhaps you can debug by catching the exception before it gets to the jsp and dumping the stack to System.out so you can see what's up in the tomcat stdout log. (Is this in a servlet or a jsp?) > the code will jump straight to the error bypassing any code of the > form > if(rst.first()) { > // do something > } I guess the first thing I'd do is something like: if (rst == null) System.out.println("rst is null"); if(rst.first()) { // do something } -Nick
On 15/08/2003 15:12 kevin wrote: > the following code frag has recently started bombing in a bean. It > produces no trappable error I can see (SQLException, Exception, > RuntimeException all fail) and is bombing at the ResultSet.first() > function call. Its using redhat 7.3 postgres jdbc pg73b1jdbcX jars. > The db is 7.3.2. jdk is sun > hotspot 1.41-b21. The sql works in a file with hard coded customer id. Have you tried catching Throwable? -- Paul Thomas +------------------------------+---------------------------------------------+ | Thomas Micro Systems Limited | Software Solutions for the Smaller Business | | Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | +------------------------------+---------------------------------------------+
nickf@ontko.com ("Nick Fankhauser") wrote in message news:<NEBBLAAHGLEEPCGOBHDGEEHLIAAA.nickf@ontko.com>... > Kevin- > > Looking at the code fragments, there's nothing obviously wrong, but we're > just seeing pieces. Given that nothing is obvious, I'd suggest it is time to > just start adding some debug statements to narrow it down... > > > a call has been made to the jsp page defined isErrorPage=true with no > > valid > > Exception object. > > exception==null > > So apparently an exception is being thrown, but is invalid by the time it > gets passed to the error page. Perhaps you can debug by catching the > exception before it gets to the jsp and dumping the stack to System.out so > you can see what's up in the tomcat stdout log. (Is this in a servlet or a > jsp?) i cant trap the exception. if i place the results.first() call in a try { } catch (SQLExcception) { } catch (Exception) { } it still jumps straight to the error page > > > > the code will jump straight to the error bypassing any code of the > > form > > if(rst.first()) { > > // do something > > } > > I guess the first thing I'd do is something like: > if (rst == null) System.out.println("rst is null"); > if(rst.first()) { > // do something > } > will try this. thanks for helping. kev. > > -Nick > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster
having gritted my teeth and removed all of my clever error trapping and replaced it with crash dump and burn output, i get to the following error message java.lang.AbstractMethodError: org.postgresql.jdbc1.Jdbc1ResultSet.first() ok, call me a plank for not trying that earlier, but have postgres jbdc developers downgraded the support? this was working until i upgraded to 7.3.2 does the jdbc1ResultSet reference imply the class is implemented in several jars that implement different levels of JDBC compliance? kev.
On 22/08/2003 14:10 kevin wrote: > having gritted my teeth and removed all of my clever error trapping > and replaced it with crash dump and burn output, i get to the > following error message > > java.lang.AbstractMethodError: > org.postgresql.jdbc1.Jdbc1ResultSet.first() > > ok, call me a plank for not trying that earlier, but have postgres > jbdc developers downgraded the support? this was working until i > upgraded to 7.3.2 > > does the jdbc1ResultSet reference imply the class is implemented in > several jars that implement different levels of JDBC compliance? ResultSet.first() is a JDBC2 method and is implemented in orh.postgresql.jdbc2.AbstractResultSet. So you'll need to use either the JDBC2 or JDBC3 driver. HTH -- Paul Thomas +------------------------------+---------------------------------------------+ | Thomas Micro Systems Limited | Software Solutions for the Smaller Business | | Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | +------------------------------+---------------------------------------------+
paul@tmsl.demon.co.uk (Paul Thomas) wrote in message news:<20030825092255.A17124@bacon>... > On 22/08/2003 14:10 kevin wrote: > > ResultSet.first() is a JDBC2 method and is implemented in > orh.postgresql.jdbc2.AbstractResultSet. So you'll need to use either the > JDBC2 or JDBC3 driver. > aha. (small, dim, lightbulb) had all 3 drivers in common dir of tomcat, search path picking jdbc1 driver. remove pg73b1jdbc2.jar and pg73b1jdbc1.jar from webserver common dir and re-run code. presto, a jdbc3 driver. thanks kev.