Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nullpointer Exception, Tomcat can't establish MySQL connection

 
Kevin Olome
Ranch Hand
Posts: 41
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am currently reading Murach's Java Servlets and JSP.

In this book there is an "musicstore" example. For some reason the Webapplication can't connect to the database.

If you have enough time and want to download the project file it is under the murach webpage. But you have to register to download the files. (Project is called musicstore)
I don't want to post copyrighted material here so I guess I can't show you the complete java files.

Here is the error message: (Apache Tomcat 8 Log)

06-May-2016 11:19:07.825 SEVERE [http-nio-8080-exec-2] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [CatalogController] in context with path [/musicStore] threw exception
java.lang.NullPointerException
at music.data.ConnectionPool.freeConnection(ConnectionPool.java:39)
at music.data.ProductDB.selectProduct(ProductDB.java:39)
at music.controllers.CatalogController.showProduct(CatalogController.java:51)
at music.controllers.CatalogController.doGet(CatalogController.java:23)


ConnectionPool free Connection


selectProduct





I am currently using Arch Linux and the first Error I could fix was that the mysql connector file couldn't be deployed because of missing permissions in /usr/share.

Now it can deploy the mysql file I guess because there is no error message.

I can check the database and find entries for product. (I use netbeans and have the connection file for music and murach databases)


bigger image: http://i.imgur.com/Ejw8YPV.png

I guess netbeans can't get the values from the database.
 
Kevin Olome
Ranch Hand
Posts: 41
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem solved:
Wrong Password in context xml

Sorry that I bothered you.
 
Dave Tolls
Ranch Hand
Posts: 2110
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be either using a try-with-resources block, or at least checking if c is null (which it will be if it fails to get a connection).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic