This content has been marked as final.
Show 2 replies
-
1. Re: How to get connection in java class from datasource to execute sql
salski22 Oct 19, 2009 5:14 PM (in response to valatharv)You probably have persistance.xml that pints to your xxx-ds. In persistance.xml you should have persistance-unit name something like
<persistence-unit name="dsname">
then in your class you point to your EntityManager
public class ValidateUtil { private EntityManager dsname; //and something like that Query q = dsname.createQuery("select * from ....") .... }
-
2. Re: How to get connection in java class from datasource to execute sql
blabno Oct 19, 2009 10:44 PM (in response to valatharv)From POJO use JNDI. From EJB use @Resource to inject datasource i.e.:
@Resource(mappedName="java:/DefaultDS") DataSource dataSource;