Search code examples
jpapersistenceejbear

Accessing persistance file from another project


I have an EJB project setup in the following way

EAR Project
    EJB Proj
    EJB Client Proj
    JPA Proj
    Web Proj

I am in current need to use the persistance.xml file from the JPA proj to query the db from a servlet (in the web proj)

What would be the best way to gain access to this? Thanks Jon


Solution

  • You do not need persistance.xml file to get the access to database connection. In the web project you can get database connection by JNDI lookup.

    Try something:

    InitialContext ctx = new InitialContext();<br>
    Connection con = ((DataSource)ctx.lookup("Con-Pool-Name")).getConnection();