Hello
i have specified a mysql server in my perstience.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="HelloWorld" transaction-type="RESOURCE_LOCAL">
<class>model.MyUser</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/database"/>
<property name="javax.persistence.jdbc.user" value="username"/>
<property name="javax.persistence.jdbc.password" value="password"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
I my Servlet i try to read from the MySQL-DB
emf = Persistence.createEntityManagerFactory("HelloWorld");
MyUser user = (MyUser)emf.createEntityManager().createQuery("select u from MyUser u").getResultList().get(0);
MyUser is the perstient class for the database table
@Entity
@Table(name="myuser")
public class MyUser implements Serializable {
....
}
If i try to take a look on the Servlet i get the following exception
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException: Fehler beim Herstellen der Verbindung zum Server localhost am Port 1527. Nachricht: Verbindungsaufbau abgelehnt.
Error Code: 0
The MySQL Server is running on 3306, so i think my persistence.xml isn't used, how can i change this?
[Message sent by forum member 'tallan']
http://forums.java.net/jive/thread.jspa?messageID=480664