You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Rajender Vallapureddy <ra...@hnexus.com> on 2013/01/05 15:35:36 UTC

opening database connection in custom mailet

Hi Eric,

I have a requirement where I need to open database connection within
my custom mailet. Is there any connection API within james that I can
use and make queries to the database.


Would appreciate your help :)

Thank you,
Regards,
Rajender

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Re: opening database connection in custom mailet

Posted by Eric Charles <er...@apache.org>.
Hi,

You should be able to use the jpa entityManagerFactory by defining a 
field in your mailet

@PersistenceUnit
private EntityManagerFactory entityManagerFactory;

Invoke in your code to get an entityManager:
EntityManager entityManager = entityManagerFactory.createEntityManager();

This will be configured based on the james-database.properties file.

 From there, it's plain JPA, where plain JDBC is also supported 
(entityManager.createNativeQuery).

Thx, Eric


On 05/01/2013 15:35, Rajender Vallapureddy wrote:
> Hi Eric,
>
> I have a requirement where I need to open database connection within
> my custom mailet. Is there any connection API within james that I can
> use and make queries to the database.
>
>
> Would appreciate your help :)
>
> Thank you,
> Regards,
> Rajender
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org