我正在制作一个简单的注册程序,因为我点击提交到我的IDE日志中我收到此错误:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:8888/login
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Register.doPost(Register.java:18)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
13-May-2014 10:09:48.900 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\apache-tomcat-8.0.5\webapps\manager
进入我的IDE似乎已成功连接database
。
甚至我已经将Mysql连接器添加到库中。
这是我的屏幕截图click here
PLZ帮助,帮助将不胜感激!!
这是我的Registration.java
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Register extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String n=request.getParameter("name");
String p=request.getParameter("password");
String e=request.getParameter("email");
String c=request.getParameter("userCountry");
try{
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:8888/login", "root", "1234"
);
PreparedStatement ps=con.prepareStatement("insert into REGISTERUSER values(?, ?, ?, ?)");
ps.setString(1,n);
ps.setString(2,p);
ps.setString(3,e);
ps.setString(4,c);
int i=ps.executeUpdate();
if(i>0){
out.print("Registered successfully..");
}
}catch(Exception d){d.printStackTrace();}
out.close();
}
}
这是我的html文件register.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="Register" method="post">
Name: <input type="text" name="name">
Email: <input type="text" name="email">
Password: <input type="password" name="password">
Country:
<select name="userCountry">
<option>India</option>
<option>Pakistan</option>
<option>Other</option>
</select><br><br>
<input type="submit" value="register">
</form>
</body>
</html>
答案 0 :(得分:1)
在Java Web应用程序中,第三方库位于WEB-INF / lib文件夹中。复制此文件夹中的jar并重新部署您的应用程序。如果您的应用程序应在每个应用程序服务器(Tomcat,Jetty,JBoss,GlassFish等)上支持这些库,请执行此操作。
答案 1 :(得分:1)
没有合适的驱动程序表明类加载器找到了JAR,但是您的连接URL不正确。
以下是Connector / J的MySQL文档:
http://dev.mysql.com/doc/refman/5.0/en/connector-j-info.html
MySQL的默认端口是3306.您确定本地主机正在监听8888吗?
错误的代码。 Scriptlet不属于JSP。您不会关闭finally块中的任何SQL资源。
答案 2 :(得分:0)
1)将驱动程序jar文件添加到构建路径
2)在代码中添加Class.forName("com.mysql.jdbc.Driver");
。
例如:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:8888/login", "root", "1234"
);