[Logo]
Forums Register Login
Nullpointer Exception, Tomcat can't establish MySQL connection
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.
problem solved:
Wrong Password in context xml

Sorry that I bothered you.
(1 like)
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).
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Sep 23, 2017 09:17:27.