3rdempire 发表于 2009-8-2 23:06:02

一个简单的问题

<%@ page contentType="text/html; charset=gb2312"
%>
<%@ page language="java"
%>
<%@ page import="com.mysql.jdbc.Driver"
%>
<%@ page import="java.sql.*"
%>
<html>
<body>
<%
//驱动程序名

String driverName="com.mysql.jdbc.Driver";

//数据库用户名

String userName="root";

//密码

String userPasswd="123456";

//数据库名

String dbName="student";

//表名

String tableName="studentinfo";

//联结字符串

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection conn=DriverManager.getConnection(url);

Statement statement = conn.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();

conn.close();

%>
</body>
</html>



我先前已经把mysql-connector-java-5.0.4-bin.jar复制到TOMCAT6.0了,现在上面的代码放到webapps/JDBC下的JSP中
http://localhost:8080/jdbc/a.jsp 还是运行不出啊

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 /a.jsp at line 37

34:
35:Class.forName("com.mysql.jdbc.Driver").newInstance();
36:
37:Connection conn=DriverManager.getConnection(url);
38:
39:Statement statement = conn.createStatement();
40:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.a_jsp._jspService(a_jsp.java:149)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:812)
com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3269)
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1182)
com.mysql.jdbc.Connection.createNewIO(Connection.java:2670)
com.mysql.jdbc.Connection. <init>(Connection.java:1531)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.a_jsp._jspService(a_jsp.java:92)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
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.

kider 发表于 2009-8-4 17:48:59

提示的是权限问题...,检查MySQL用户权限

my1bbs1 发表于 2016-2-2 09:44:06

看看












http://js.ufstone.net/img/sigline.gif
北京华盛癫痫病医院好吗
北京癫痫病专科医院排名
北京华盛癫痫病医院
昆明军海癫痫病医院
昆明军海医院怎么样
北京华盛癫痫病医院
北京华盛癫痫病医院
云南昆明军海医院
北京华盛医院怎么样
昆明军海癫痫病医院
北京华盛癫痫病医院
昆明军海癫痫病专科医院
页: [1]
查看完整版本: 一个简单的问题