简体   繁体   English

通过glassfish服务器访问mysql数据库时,访问被拒绝

[英]access denied when accessing mysql database through glassfish server

I'm following a tutorial which uses GlassFish to access a mysql database in NetBeans. 我正在学习使用GlassFish访问NetBeans中的mysql数据库的教程。 The problem is I'm getting this error 问题是我遇到此错误

Internal Exception: java.sql.SQLException: Error in allocating a connection. 内部异常:java.sql.SQLException:分配连接时出错。 Cause: Connection could not be allocated because: Access denied for user 'root'@'localhost' (using password: NO) 原因:无法分配连接,因为:用户'root'@'localhost'的访问被拒绝(使用密码:NO)

when I try to deploy my app. 当我尝试部署我的应用程序时。 I understand I need to add the password to the configuration so that GlassFish can establish the connection. 我知道我需要在配置中添加密码,以便GlassFish可以建立连接。 The problem is I'm not sure where to include it within the persistence file. 问题是我不确定将其包含在持久性文件中的位置。

 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="com.mycompany_MyApp_ejb_1.0-SNAPSHOTPU" transaction-type="JTA"> <jta-data-source>jdbc/creditpurchase</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties/> </persistence-unit> </persistence> 

You can edit properties in glassfish admin console. 您可以在glassfish管理控制台中编辑属性。 Resources->JDBC->Connections Pools->your_connection_pool in Additional Properties tab. 其他属性选项卡中的资源-> JDBC->连接池->您的连接池。 You can add property with name password. 您可以使用名称密码添加属性。 take a look here . 看一下这里

I was able to do it here: 我能够在这里做到:

C:\Code\Java\Glassfish\glassfish3\glassfish\domains\domain1\config\domain.xml

Change the properties within the jdbc-connection-pool tag 更改jdbc-connection-pool标记内的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM