Reputation: 75
I'm trying to use a MySQL database with EclipseLink using Netbeans but I keep getting this EJB-exception when the application is about to get data out of the database:
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Access denied for user 'root'@'localhost' (using password: NO)
As you can see 'using password' is set to NO but this should be YES because I have a password set for accessing the mysql server. I already saved the password in the properties of my server and I can browse through the several databases it contains.
This is my 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>
Is there a way of letting EclipseLink provide a password? Or could there be an other problem?
Upvotes: 1
Views: 3250
Reputation: 7306
You can add user and password to persistence.xml by
<property name="eclipselink.jdbc.user" value=""/>
<property name="eclipselink.jdbc.password" value=""/>
By the way you have a JTA Datasource.I think user and password should be in the DS file.
Upvotes: 2
Reputation: 3814
I usually supply passwords directly in persistence.xml
:
<property name="javax.persistence.jdbc.password" value="MYPW"/>
Doesn't depend on eclipselink as in bilash.saha's answer.
Upvotes: 2