myeclipse已经和mysql连接成功了,但是为什么运行java文件,还是报错啊
packagecom.imooc.db;importjava.sql.Connection;importjava.sql.DriverManager;importjava...
package com.imooc.db;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class DBUtil { private static final String URL="jdbc:mysql://127.0.0.1:3306/imooc"; private static final String USER="root"; private static final String PASSWORD="root"; public static void main(String[] args) throws Exception{ try{ //1.加载驱动程序 Class.forName("com.mysql.jdbc.Driver"); //2.获得数据库的连接 Connection conn=DriverManager.getConnection(URL, USER, PASSWORD); //3.通过数据库的连接操作数据库,实现增删改查 Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery("select user_name,age from imooc_goddness"); while(rs.next()){ System.out.println(rs.getString("user_name")+","+rs.getInt("age")); } } catch(ClassNotFoundException e){ e.printStackTrace(); }catch(SQLException e){ e.printStackTrace(); } }}报错的内容如下:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:911)然后等等...
展开
2个回答
2017-02-25
展开全部
MYSQL的登录不对
~~~~~~~~~~~
~~~~~~~~~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询