• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nullpointer Exception, Tomcat can't establish MySQL connection

 
Ranch Hand
Posts: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 44
1
Android Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem solved:
Wrong Password in context xml

Sorry that I bothered you.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic