【问题标题】:java.sql.SQLException: Access denied for user 'userapp'@'localhost' / glassfishjava.sql.SQLException:用户“userapp”@“localhost”/glassfish 的访问被拒绝
【发布时间】:2015-10-27 21:59:29
【问题描述】:

我正在尝试使用注入到 servlet (glassfish) 中的 javax.sql.DataSource

@Resource (name="jdbc/MysqlDS" )
javax.sql.DataSource mysqlDS;

以下语句失败,抛出“java.sql.SQLException: Access denied for user 'userapp'@'localhost' (using password: YES)”:

con=mysqlDS.getConnection();
PreparedStatement pstmt=con.prepareStatement("select now()");

con=mysqlDS.getConnection("userapp","userpassword");
PreparedStatement pstmt=con.prepareStatement("select now()");

但以下是成功的:

Class.forName("com.mysql.jdbc.Driver");
con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/user_lindenb", "appuser", "userpassword");
w.println("OK");
con.close(); con=null;

con=mysqlDS.getConnection("root","root_password");

con=mysqlDS.getConnection("me","mypassword");

$ mysql -u appuser --password=userpassword -D user_lindenb -e 'select now()'
+---------------------+
| now()               |
+---------------------+
| 2015-08-05 10:19:07 |
+---------------------+

赠款声明如下:

 grant insert,select,update,delete on user_lindenb.* TO 'appuser'@'localhost' identified by 'userpassword';

资源声明如下

asadmin --port  8138 create-jdbc-connection-pool \
            --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource \
            --restype javax.sql.DataSource \
            --property "password=userpassword:user=userapp:serverName=localhost:databaseName=user_lindenb" \
             MysqlDS
asadmin --port 8138 create-jdbc-resource \
            --connectionpoolid MysqlDS \
            "jdbc/MysqlDS"

这个用户 'userapp' 有什么问题?

谢谢。

【问题讨论】:

    标签: java mysql jdbc glassfish asadmin


    【解决方案1】:

    在我添加之后

    grant USAGE on *.* TO 'appuser'@'localhost' identified by 'adminadmin';
    

    一切正常...我不明白为什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-10
      • 2021-08-05
      • 2020-09-12
      • 2020-03-18
      • 2012-08-08
      • 2012-08-11
      • 2020-09-02
      • 1970-01-01
      相关资源
      最近更新 更多