users@glassfish.java.net

Re: problem connecting to database using JPA

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Thu, 18 Oct 2007 13:51:08 -0700

As suggested by Marina, please check whether the database is actually
up. Please also note that the database connection would be made when the
second line is executed (that is when first em from a given emf is created)

glassfish_at_javadesktop.org wrote:
> I'm trying to execute following two lines of code WITHOUT previous connection to the database.
>
> EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);
> EntityManager em = emf.createEntityManager();
>
> I am able to successfully pass first line. The EntityManagerFactory is created. On the second line I'm getting
> Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.DatabaseException
> Internal Exception: java.sql.SQLTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.Error Code: -4499
>
> In the persistence.xml under persistenceUnitName there is all the information required for connection:
> <properties>
> <property name="toplink.jdbc.user" value="mike"/>
> <property name="toplink.jdbc.password" value="mike"/>
> <property name="toplink.jdbc.url" value="jdbc:derby://localhost:1527/MyTest"/>
> <property name="toplink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
> </properties>
>
> I'm using NetBeans 5.5 with internal Tomcat 5.5.17 and Derby as a database.
> How can I obtain database connection from java code using JPA?
> Please help.
> [Message sent by forum member 'javmike' (javmike)]
>
> http://forums.java.net/jive/thread.jspa?messageID=241037
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>