0

I created a small website in Netbeans, with JSP and MySQL. I'm experiencing a very strange problem:

I upload the war file to the server and the website runs without problems for a few days - Then out of the blue, the jar file stops working and the website does not display any of the information from the database.

I tried uploading the jar file to the lib directory on the Apache Tomcat server, but that did not solve the problem.

Has anyone experienced this before?

user1163278
  • 411
  • 6
  • 20

1 Answers1

0

That can happen if the code doesn't close() DB resources such as Connection, Statement and ResultSet properly in the finally block after use, which is a pretty common starters mistake. The DB will then run out of those resources after some time. That can also happen if the code is acquiring the DB connection on webapp startup only and using the one and same for connection for the remnant of the webapp's lifetime instead of acquiring it at the moment the SQL query is to be executed. A DB resource which is kept open for too long will timeout sooner or later.

I would also look at exception handling in your code. You should surely have gotten a SQLException whenever this problem occurs. It look like that the code is swallowing the SQLException by an empty catch block or by a catch block which does nothing else than printing it to the server log (which you maybe never have read). The code should never continue the flow whenever an exception occurs but instead properly handle the exception by displaying an error page. This is also a common starters mistake.

All with all, you can find a basic kickoff example of the proper approach in this answer: Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern.

Note that this has nothing to do with "the JAR file not working". This makes at its own absolutely no sense.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555