夜深了还在为关于jsp+tomcat+mysql数据库连接的问题头痛!请高手帮忙
我在tomcat容器编译时DOS中提示 java.lang.ClassNotFoundException
com.mysql.jdbc.Driver
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException
org.apache.jsp.first_jsp._jspService(first_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
下面是数据库的连接代码
package com.netshop;
import java.sql.*;
public class OpenDB
{
String userName= "root ";
String userPassword= "123456 ";
private String driverName = "com.mysql.jdbc.Driver ";// "org.gjt.mm.mysql.Driver ";(两种加载驱动程序方式都不行)
private String url = "jdbc:mysql://localhost/netshop?useUnicode=true&characterEncoding=gb2312 ";
Connection dbConn;
public OpenDB()
{
}
public Connection getConnection()
{
try
{
Class.forName(driverName);
dbConn=DriverManager.getConnection(url,userName,userPassword);
}
catch(Exception ex)
{
System.out.println(ex.toString());
dbConn = null;
}
return dbConn;
}
}
MySQL 版本是5.0.21 不知道是不是驱动器的原因还是?如果是的话应该要哪个版本的驱动器,该在哪里存放驱动的什么文件呢? 麻烦武林高手 在这深夜能出手相助,小弟在此感激不尽!
[解决办法]
你没有加驱动包吧
[解决办法]
把驱动包放到Tomcat\common\lib下,再在classpath里设置驱动包的路径就行了
我曾经也碰到过这样的问题,不过我用的是SQLSERVER2000。
[解决办法]
找不到驱动.加载包就行了
[解决办法]
驱动应放在WEB-INF/lib中
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html