我正在使用tomcat 6.0 这是我的卡塔利娜家 - > C:\ Program Files \ Apache Software Foundation \ Tomcat 6.0
我正在使用jdk 1.6 这是我的JAVA_HOME C:\ Program Files \ Java \ jdk1.6.0_24
我正在使用Windows 7
好的我写了一个jsp页面 这是代码 它保存在 - > C:\ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ webapps \ myapp \ wow.jsp
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://localhost:3306/unni";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
%>
<%
Class.forName("com.mysql.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "footyfreak");
statement = connection.createStatement();
rs = statement.executeQuery("SELECT * FROM unni");
while (rs.next()) {
out.println(rs.getString("player")+"");
}
rs.close();
%>
我下载了连接器并将其复制到: - C:\ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ webapps \ myapp \ WEB-INF \ lib \ mysql-connector-java-5.1.15-bin.jar
也是 C:\ Program Files \ Apache Software Foundation \ Tomcat 6.0 \ lib \ mysql-connector-java-5.1.15-bin.jar
然后当我点击url http://localhost:8080/myapp/wow.jsp
我收到错误,因为--------------&gt;
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /wow.jsp at line 12
9:
10:
11: <%
12: Class.forName("com.mysql.Driver").newInstance();
13: connection = DriverManager.getConnection(connectionURL, "root", "footyfreak");
14: statement = connection.createStatement();
15: rs = statement.executeQuery("SELECT * FROM unni");
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:519)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.wow_jsp._jspService(wow_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.ClassNotFoundException: com.mysql.Driver
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:128)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
java.lang.Class.forName0(Native Method)
java.lang.Class.forName(Unknown Source)
org.apache.jsp.wow_jsp._jspService(wow_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.32 logs.
Apache Tomcat/6.0.32
我的类路径详细信息是
variable : CLASSPATH
value : C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar ; C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\mysql-connector-java-5.1.15-bin.jar;
帮帮我。我已经坐了好几天了。
我在文档中做了。
除了这里提到的什么之外还有什么需要做的吗?
答案 0 :(得分:3)
java.lang.ClassNotFoundException:com.mysql.Driver
班级名称错了。它是com.mysql.jdbc.Driver
。
Class.forName("com.mysql.jdbc.Driver");
那个newInstance()
电话是多余的。请注意,将所有代码放在JSP文件中是一种不好的做法。该代码通常应该在您在servlet中使用的普通Java类中。另请注意,运行Tomcat时,CLASSPATH
环境变量完全被忽略。
答案 1 :(得分:0)
connection = DriverManager.getConnection(connectionURL,“root”,“footyfreak”);
在此connectionURL语句中,您要提供数据库名称。例:
String st="jdbc:mysql://localhost:3306/staff";
Connection con=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(st,"root","admin" );
在此示例中,staff是我的数据库名称。
在这样给出之后,我没有收到该错误消息。
答案 2 :(得分:0)
而不是添加外部jar将jar文件复制到以下位置
WEB-INF/lib