tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: OpenEJB - Datasource lookup problem
Date Tue, 13 May 2008 17:49:01 GMT
With a Resource declared as follows:

<Resource id="MyDatasource" type="Datasource">
    JdbcDriver   org.gjt.mysql.Driver
    JdbcUrl      jdbc:mysql://localhost:3306/test_db
    UserName     root
    Password     12345
    jtamanaged   true
</Resource>

You could have it injected via:

   @Resource(name="MyDatasource")
   private DataSource ds;

Or the non-annotated way of using the ejb-jar.xml and jndi as follows:

  [ejb-jar.xml]
   <resource-ref>
     <res-ref-name>MyDatasource</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
   </resource-ref>

  [bean code]
   Context ctx = new InitialContext();
   Datasource ds = (Datasource) ctx.lookup( "java:comp/env/ 
MyDatasource" );



Here's a working example of the annotated approach if it helps:

   http://openejb.apache.org/3.0/injection-of-datasource-example.html

-David


On May 12, 2008, at 11:16 PM, BraamB wrote:

>
> Hallo,
>
> Were you able to fix this problem? I am using the embedded openEJB  
> with
> Tomcat 6 and have the exact same problem. I keep getting
> NameNotFoundException. Could you please help?
>
>
>
>
> ManojS wrote:
>>
>> Hello,
>>
>> I was playing with openejb and a test ejb application in my  
>> machine. My
>> intention was to identify how much openejb is useful for me as an ejb
>> container, so that I can recommend to use at my workplace. While I  
>> was
>> trying to integrate openejb along with the application I cannot  
>> able to
>> lookup the datasource connection defined in the openejb.conf file.  
>> If I
>> explain in detail, my openejb.conf has the following connection
>> configuration.
>>
>> <Connector id="MyDatasource" type="Datasource">
>>    JdbcDriver   org.gjt.mysql.Driver
>>    JdbcUrl      jdbc:mysql://localhost:3306/test_db
>>    UserName     root
>>    Password     12345
>>    jtamanaged   true
>> </Connector>
>>
>> I am using the "Default Stateless Container" with  
>> ctype="STATELESS". And
>> my ejb code (my ejbs are stateless session beans) for datasource  
>> lookup is
>> as follows,
>>
>> public Connection getConnection () throws Exception {
>> 	Context ctx = new InitialContext();
>> 	Datasource ds = (Datasource) ctx.lookup( "MyDatasource" );
>> 	return (ds!=null?ds.getConnection():null);
>> }
>>
>> This code is throwing a javax.naming.NameNotFoundException. I tried  
>> with
>> various other JNDI names like "java:comp/MyDatasource",
>> "java:openejb/MyDatasource" etc. But the same result.
>>
>> The openejb version I am using is 1.0, because the EJB version I  
>> was using
>> is 2.0.
>>
>> Can anyone help me to figure out what is the JNDI name to use for
>> connector lookup ?
>>
>> Thanks in advance.
>>
>> Manoj.
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/OpenEJB---Datasource-lookup-problem-tp14645858p17201828.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>


Mime
View raw message