JSP:MySQL jar文件停止工作 [英] JSP: MySQL jar file stops working

查看:128
本文介绍了JSP:MySQL jar文件停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JSP和MySQL在Netbeans中创建了一个小型网站。我遇到了一个非常奇怪的问题:

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

我将war文件上传到服务器,网站运行几天没有问题 - 然后突然出现了, jar文件停止工作,网站不显示数据库中的任何信息。

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.

我尝试将jar文件上传到Apache Tomcat服务器上的lib目录,但是那并没有解决问题。

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?

推荐答案

代码不是 close()数据库资源,例如连接 Statement ResultSet 在使用后正确地在 finally 块中,这是一个非常常见的启动器错误。一段时间后,DB将耗尽这些资源。如果代码仅在webapp启动时获取数据库连接并使用同一个连接来获取webapp生命周期的剩余而不是在执行SQL查询时获取它,也会发生这种情况。保持打开时间过长的数据库资源迟早会超时。

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.

我还会查看代码中的异常处理。发生此问题时,您肯定会得到 SQLException 。看起来代码是通过一个空的catch块或一个catch块吞下 SQLException ,除了将它打印到服务器日志(你可能永远不会有)读)。每当发生异常时,代码都不应该继续流程,而是通过显示错误页面来正确处理异常。这也是常见的首发错误。

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.

总而言之,您可以在此答案中找到正确方法的基本启动示例:使用MVC和DAO模式在JSP页面中显示HTML中的JDBC ResultSet

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.

请注意,这与JAR文件无法正常工作无关。这完全没有任何意义。

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

这篇关于JSP:MySQL jar文件停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆