MariaDB社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3431|回复: 3
打印 上一主题 下一主题

一个简单的问题

[复制链接]
跳转到指定楼层
1#
发表于 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.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖 顶 踩
2#
发表于 2009-8-4 17:48:59 | 只看该作者
提示的是权限问题...,检查MySQL用户权限
3#
发表于 2016-2-2 09:44:06 | 只看该作者
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|MariaDB社区 ( 京ICP备07012489号    |
业务联系: QQ:48474881; 邮箱: 48474881@qq.com; 电话:13911732319
声明:本站部分文章是网友转载,若未经作者同意或署名有误,请联系网站管理员。

GMT+8, 2024-11-1 16:36 , Processed in 0.114032 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表