Bear Bibeault wrote:Why is everything static?
David Borchgrevink wrote:we're getting a nullpointer at line 94 (result = stmt.executeQuery(query);) of his class.
Paul Clapham wrote:
David Borchgrevink wrote:we're getting a nullpointer at line 94 (result = stmt.executeQuery(query);) of his class.
Then that means the "stmt" variable is null.
Which would be because it's never assigned a value. Which would in turn be because the line of code before its assignment ("DriverManager.getConnection...") threw an exception. Which you should be able to find about because those exceptions are logged somewhere.
Paul Clapham wrote:Really that catch-block in the PDB class should be throwing a RuntimeException after logging the SQLException; as it's written it basically ignores the SQLException and allows processing to go on until something else fails. You noticed already how hard it is to track down the reason for the secondary failure, right?
Paul Clapham wrote:The primary problem was that the driver didn't load. The secondary problem was that you had a NPE elsewhere. It wasn't obvious to you that the secondary problem was because the primary problem had been ignored.
Paul Clapham wrote:Classpath? Yes... but you posted some code for a servlet, so am I right in assuming that you're running this in some servlet environment like Tomcat? If so then the driver jar should go in the web application's WEB-INF/lib folder.
Paul Clapham wrote:You don't need the Class.forName line if two conditions apply: (1) you're using Java 6, and (2) the driver is JDBC 4.0 compatible. You should certainly be using Java 6 by now, and the latest version of the driver should certainly support JDBC 4.0, but anyway you should really ensure that both of those conditions do apply.
Paul Clapham wrote:Here's my opinion: you've got a whole lot of code and it's all untested. And servlets are a really poor testing environment. So why don't you back up a bit -- write a command-line program which tests your database access, to get that working first. Then you can put the working code into the servlet.
This tiny ad will self destruct in five seconds.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|