使用TOMCAT5.5连接Mysql数据库,使用的是mysql-connector-java-5.0.4-bin驱动连接。
把驱动放到了G:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib文件夹下,并且在系统变量里已经定义。
写了一段测试程序,如下:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*"%>
<head>
</head>
<body>
<%
String url = "jdbc:mysql://localhost:3306/test?user=root&password=123";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
out.print("connect succeed");
%>
</body>
运行http://localhost:8080/test.jsp。报出如下错误:
exception
org.apache.jasper.JasperException: com.mysql.jdbc.Driver
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.xp_jsp._jspService(xp_jsp.java:62)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1362)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1208)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:125)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.xp_jsp._jspService(xp_jsp.java:49)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
万分紧急 跪求达人解惑 ~
--转自