我正在使用tomcat6在eclipse中运行servlet文件。运行我的文件时,它显示以下错误:
错误 处理资源'http:// localhost / MyFirstDynaSer / SignUp ...
java.sql.SQLException:握手期间的通信失败。是 有一个服务器在localhost上运行:3306?“
我的错误是什么?有人可以帮帮我..这是我的web.xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>SignUp</servlet-name>
<servlet-class>com.authentication.org.SignUp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SignUp</servlet-name>
<url-pattern>/SignUp</url-pattern>
</servlet-mapping>
<display-name>MyFirstDynaSer</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306?
at com.mysql.jdbc.MysqlIO.init(Unknown Source)
at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source)
at com.mysql.jdbc.Driver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.foofy.org.DbConnection1.DbConn(DbConnection1.java:28)
at com.authentication.org.SignUp1.doGet(SignUp1.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:404)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at com.authentication.org.SignUp1.doGet(SignUp1.java:74)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:404)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
答案 0 :(得分:1)
驱动程序类由JVM成功加载,确切的问题是你使用的是最新的mysql服务器,但是旧版本的mysql连接器jar。
建议:
转到 下载mysql connectro http://dev.mysql.com/downloads/connector/j/3.1.html/ 并下载最新的驱动程序并将其放入您的WEB-INF / lib目录,重启服务器
祝你好运。答案 1 :(得分:0)
我所犯的错误是我没有将我的jar文件包含在Web-INf \ lib文件夹中。 和 我没有在java构建路径中包含jar文件。这可以通过右键单击您的项目,单击属性,选择java内置路径,库选项卡,选择添加extenal jar并选择您的mysql连接器jar文件来完成..希望它有助于像我一样天真。
ps:运行mysql服务的端口没有问题。该端口默认为3306。