JSP连接Mysqld的问题——连不上 收藏
|
楼主发表于: 2007-03-28 10:45:44
环境变量的设置:(应该没问题,测试的Java,JSP,Severlet,JavaBean均通过,Java和Connector都是5.0以上的版本,Tomcat也是最新的)
.; %JAVA_HOME%libdt.jar; %JAVA_HOME%lib ools.jar; %JAVA_HOME%libmysql-connector-java-5.0.5-bin-g.jar; %JAVA_HOME%mysql-connector-java-5.0.5mysql-connector-java-5.0.5-bin.jar; %TOMCAT_HOME%commonlibservlet.jar 不连接数据库,只将 html><body><center> Now time is: <%=new java.util.Date()%> </center></body></html> 存放到Tomcat下的相应位置,运行正常。当需要连接Mysql时,Tomcat报错: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: Only a type can be imported. com.mysql.jdbc.Driver resolves to a package org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: Only a type can be imported. com.mysql.jdbc.Driver resolves to a package org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414) org.apache.jasper.compiler.Compiler.compile(Compiler.java:297) org.apache.jasper.compiler.Compiler.compile(Compiler.java:276) org.apache.jasper.compiler.Compiler.compile(Compiler.java:264) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs. 这是怎么回事啊。 另付程序代码: <%@ page contentType="text/html; charset=gb2312" %> <%@ page language="java" %> <%@ page import="com.mysql.jdbc.Driver" %> <%@ page import="java.sql.*" %> <% //驱动程序名 String driverName="com.mysql.jdbc.Driver"; //数据库用户名 String userName="root"; //密码 String userPasswd=""; //数据库名 String dbName="test"; //表名 String tableName="t_gbk"; //联结字符串 String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection=DriverManager.getConnection(url); Statement statement = connection.createStatement(); String sql="SELECT * FROM "+tableName; ResultSet rs = statement.executeQuery(sql); //获得数据结果集合 ResultSetMetaData rmeta = rs.getMetaData(); //确定数据集的列数,亦字段数 int numColumns=rmeta.getColumnCount(); // 输出每一个数据值 out.print("id"); out.print("|"); out.print("num"); out.print("<br>"); while(rs.next()) { out.print(rs.getString(1)+" "); out.print("|"); out.print(rs.getString(2)); out.print("<br>"); } out.print("<br>"); out.print("数据库操作成功,恭喜你"); rs.close(); statement.close(); connection.close(); %> |
|
#1 得分:0回复于: 2007-03-28 10:59:29
mysql-connector-java-5.0.5-bin-g.jar这个文件应该拷贝到tomcat的lib目录下
|