mysql数据库驱动加载失败!

fs759624 2010-07-08 12:36:04
错误提示:

驱动我也放到lib里面了。
源代码:
package first.second.three;

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;

public class loginServlet extends HttpServlet
{
private String url;
private String user;
private String password;

public void init() throws ServletException
{
ServletContext sc=getServletContext();
String driverClass=sc.getInitParameter("driverClass");
url=sc.getInitParameter("url");
user=sc.getInitParameter("user");
password=sc.getInitParameter("password");
try
{
Class.forName(driverClass);
}
catch(ClassNotFoundException ce)
{
throw new ServletException("加载数据库驱动失败!");
}
}

public void doGet (HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
req.setCharacterEncoding("gb2312");
String condition1=req.getParameter("username");
String condition2=req.getParameter("password");
if (condition1==""||condition2=="")
{
resp.sendRedirect("loginFail.html");
return;
}
resp.setContentType("text/html;charset=gb2312");
PrintWriter out=resp.getWriter();
try
{
conn=DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
if(condition1!=""&&condition2!="")
{
rs=stmt.executeQuery("select stu_pwd from stu_info where stu_id=condition1");
if(rs.next())
{
if(rs.getString("stu_pwd")==condition2)
{
resp.sendRedirect("loginSuccess.html");
}
else
{
resp.sendRedirect("loginFail1.html");
}
}
else
{
resp.sendRedirect("loginFail2.html");
}
}

}
catch (SQLException se)
{
se.printStackTrace();
}
}
}
求高手帮解决下
...全文
540 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fk1987614 2010-07-12
  • 打赏
  • 举报
回复
你可以先写个简单的直接写在Servlet中试试,如
public void service(HttpServletRequest request,
HttpServletResponse response){
try{ String driver="com.mysql.jdbc.Driver";
Class.forName(driver);
String url="jdbc:mysql://127.0.0.1:3306/student";
String user="root";
String pwd="123456789";
Connection con=DriverManager.getConnection(url,user,pwd);
Statement stt=con.createStatement();
先写个简单点的然后再测。
  • 打赏
  • 举报
回复
写的太复杂了,驱动包放在项目也可放在tomcat/lib中两个都放放试试
person_java 2010-07-08
  • 打赏
  • 举报
回复
把你的web.xml配置传上来!
Jay_xiaolei 2010-07-08
  • 打赏
  • 举报
回复

驱动找不到

驱动是放在tomcat下面的lib里面吗?
fs759624 2010-07-08
  • 打赏
  • 举报
回复
哦、
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: 加载数据库驱动失败!
first.second.three.loginServlet.init(loginServlet.java:27)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
java.lang.Thread.run(Unknown Source)
浏览器提示的错误、 谢谢你了
Jay_xiaolei 2010-07-08
  • 打赏
  • 举报
回复
错误提示是什么都不贴出来怎么帮你解决
lovebai0210 2010-07-08
  • 打赏
  • 举报
回复
咋添加commons-pool jar啊?
hoojo 2010-07-08
  • 打赏
  • 举报
回复
[Quote=引用楼主 fs759624 的回复:]
错误提示:

驱动我也放到lib里面了。
源代码:
package first.second.three;

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;

public class loginServlet extends HttpServl……
[/Quote]
将你的url,username、password打印出来看看对不对
xushilin000000000 2010-07-08
  • 打赏
  • 举报
回复
添加
commons-pool jar
fs759624 2010-07-08
  • 打赏
  • 举报
回复
改了、又有错误了!
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception

root cause

java.lang.NoClassDefFoundError: java/sql/SQLClientInfoException
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
com.mysql.jdbc.ConnectionImpl.<clinit>(ConnectionImpl.java:267)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
first.second.three.loginServlet.doGet(loginServlet.java:48)
first.second.three.loginServlet.doPost(loginServlet.java:78)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
Jay_xiaolei 2010-07-08
  • 打赏
  • 举报
回复
驱动要放在tomcat/lib下面
fs759624 2010-07-08
  • 打赏
  • 举报
回复
F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\sy\WEB-INF\lib下放置的驱动
F:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\sy\WEB-INF下 web.xml内容:
<?xml version="1.0" encoding="gb2312"?>
<web-app version="2.5">

<context-param>
<param-name>driverClass</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</context-param>

<context-param>
<param-name>url</param-name>
<param-value>jdbc:mysql://localhost:3306/student</param-value>
</context-param>

<context-param>
<param-name>user</param-name>
<param-value>root</param-value>
</context-param>

<context-param>
<param-name>password</param-name>
<param-value>12345678</param-value>
</context-param>

<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>first.second.three.loginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>

</web-app>
lemon520 2010-07-08
  • 打赏
  • 举报
回复
1.下面这句是在web.xml中读initParameter,你要检查一下web.xml中配置的driverClass参数是否正确
String driverClass=sc.getInitParameter("driverClass");
2.如果正确,就是jar包没找到

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧