返回信息流我用mysql 是可以建数据库的,但是一运行就报下面的错,还是没办法连接上数据库,完全没招,有人知道怎么解决么,哎,学个JAVA连数据库太不容易了[ema1]
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
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.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.iindex_jsp._jspService(iindex_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: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)
这是一条镜像帖。来源:北邮人论坛 / java / #33770同步于 2014/8/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
JDBC使用问题
huangqiong
2014/8/14镜像同步27 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>图书馆管理系统</title>
</head>
<body>
<center><a href=add.jsp>添加图书信息</a><P>
<table align="center" width="50%" border=1>
<tr><th>书名</th><th>作者</th><th>价格</th><th>管理</th>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","root");
Statement stmt=con.createStatement();
String sql="selet * from bookinfo";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
int id=rs.getInt(1);
out.println("<tr><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4));
}
rs.close();
stmt.close();
con.close();
%>
</table>
</center>
</body>
</html>
Access denied for user 'root'@'localhost' (using password: YES) 应该是密码错了?
但是我用MySQL commant line client 是可以直接登录的,为什么在这里就不行呢[ema16]
【 在 limingji0503 的大作中提到: 】
: Access denied for user 'root'@'localhost' (using password: YES) 应该是密码错了?
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","root");
确定不是这一句密码错了?
另外不推荐把这种纯java的写到jsp里……
很确定!!!因为我在用mysql command line client中用root是可以登录的,但是在这边就报错。另外初学所以先这样写··
【 在 wolfy 的大作中提到: 】
: Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","root");
: 确定不是这一句密码错了?
: 另外不推荐把这种纯java的写到jsp里……
而且报错pass word 中显示YES,是不是就说明我的密码没有错
【 在 wolfy 的大作中提到: 】
: Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","root");
: 确定不是这一句密码错了?
: 另外不推荐把这种纯java的写到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 /iindex.jsp at line 15
12: <tr><th>书名</th><th>作者</th><th>价格</th><th>管理</th>
13: <%
14: Class.forName("com.mysql.jdbc.Driver");
15: Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/book","root","root");
16: Statement stmt=con.createStatement();
17: String sql="select * from bookinfo";
18: ResultSet rs=stmt.executeQuery(sql);
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.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.iindex_jsp._jspService(iindex_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: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)
【 在 shan10211865 的大作中提到: 】
: String sql="selet * from bookinfo";
: ->select?