File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Servlet unable to connect to mySQL database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Servlet unable to connect to mySQL database" Watch "Servlet unable to connect to mySQL database" New topic

Servlet unable to connect to mySQL database

Chad Hunt

Joined: Jul 29, 2013
Posts: 3

Hi all,

I have created a simple web app designed to provide Java flash cards for my study. The cards are stored in a mySQL database. This web app works great when run locally through Eclipse, as well as on Jelastic. I decided to try and deploy it on my Raspberry Pi and I've run into a problem. Everything works except I can't get the database connection going. The odd thing is that if I run the app from within Eclipse and reference the DB on the Pi, it works!
I have placed the two required JARs (JDBC Connection and JSON) in every possible location Google suggests on the Pi, but to no avail.
The only error I can find while running everything on the Pi is a 500 error each time the JSP requests a flash card's data from the servlet.

I'm new to setting up Apache/Tomcat, so I'm having trouble figuring out where I can see logs that might show a stack trace similar to what I am accustomed to in Eclipse.

For the record, phpMyAdmin accesses the DB fine from the Pi as well.

Any suggestions would be greatly appreciated.
E Armitage

Joined: Mar 17, 2012
Posts: 989
Were you able to get it working locally on Tomcat? The tomcat logs should be easy to find once you find the tomcat base folder.
Chad Hunt

Joined: Jul 29, 2013
Posts: 3

Locally (on the Raspberry Pi), I can access the database via phpMyAdmin as well as through mySQL command line. Don't know if it's useful, but i have a separate PHP script that also has no issue using the database.

So far, the only logs that I have found are in, if I remember correctly, /var/lib/tomcat7/logs/ They are: catalina.out, catalina.2013-07-*.log, and a couple relating to localhost. (I'm not at my home right now to get the exact names) Catalina out shows no errors. The only error shows up in one of the localhost logs when my JSP sends a POST request for database data (error 500). This is done using AJAX, and the response from the servlet comes back as a JSON object.
Chad Hunt

Joined: Jul 29, 2013
Posts: 3

In case anyone stumbles across this, I managed to solve my own problem after many days of troubleshooting. My code was written and compiled on my Mac using Java 1.7 where everything worked fine. My Raspberry Pi, however, was only running Tomcat 6. After updating to Tomcat 7, all worked as it should. Ultimately, a simple 'duh' solution.

Hope this helps someone in the future.
I agree. Here's the link:
subject: Servlet unable to connect to mySQL database
jQuery in Action, 3rd edition