关于java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)错误

报错:

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)


代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor="#EEDDFF">
<%
Connection con;
Statement sql;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception e) {
out.println("忘记把MySQL数据库的JDBC数据库驱动程序复制到JDK的扩展目录中");
}
try {
String uri = "jdbc:mysql://localhost:3306/warehouse";
String user = "root";
String password = "acbz630756";
con = DriverManager.getConnection(uri,user,password);
sql = con.createStatement();
rs = sql.executeQuery("select * from product");
out.print("<table border=2>");
out.print("<tr>");
out.print("<th width=100>" + "产品号");
out.print("<th width=100>" + "名称");
out.print("<th width=50>" + "生产日期");
out.print("<th width=50>" + "价格");
out.print("</tr>");
while (rs.next()) {
out.print("<tr>");
out.print("<td>" + rs.getString(1) + "</td>");
out.print("<td>" + rs.getString(2) + "</td>");
out.print("<td>" + rs.getDate("madeTime") + "</td>");
out.print("<td>" + rs.getFloat("price") + "</td>");
out.print("<tr>");
}
out.print("</table>");
con.close();
} catch (SQLException e) {
out.print(e);
}
%>
</body>

</html>


报错:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

有两个原因:要么是数据库的访问的问题,要么是编码错误。

仔细一看,原来是我数据库的登陆密码错误。。。


con = DriverManager.getConnection(uri,user,password); 

若报错,须将jsp开头的jdbc的connection导入包代码删掉

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值