我试图使用Netbeans与EclipseLink使用MySQL数据库,但当应用程序正在从数据库中获取数据时,我不断收到此EJB异常:JPA。 Eclipselink没有为mySQL提供密码,但它应该
原因:javax.persistence.PersistenceException:异常[EclipseLink-4002](Eclipse持久性服务 - 2.3.0.v20110604-r9504):org.eclipse.persistence.exceptions.DatabaseException 内部异常:java.sql。 SQLException:分配连接时出错。原因:连接无法分配,因为:访问被拒绝用户'root'@'localhost'(使用密码:否)
正如你所看到的'使用密码'被设置为NO,但是这应该是YES我有一个用于访问mysql服务器的密码。我已经将密码保存在服务器的属性中,并且可以浏览它包含的几个数据库。
这是我persitence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="Project_googlePU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/programmeren_project</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
是否有让的EclipseLink提供密码的方法吗?或者还有其他问题?
非常感谢!我虽然尝试过,但后来我可能使用了错误的名称。 – user1043194
正如bilash.saha所提到的,您正在使用数据源,因此不使用密码。 EclipseLink改为从数据源获取连接 - 数据源需要使用密码进行配置。只有在Provider创建连接而不是使用数据源 – Chris