Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 33480 invoked from network); 23 Mar 2006 17:26:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Mar 2006 17:26:50 -0000 Received: (qmail 36442 invoked by uid 500); 23 Mar 2006 17:26:45 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 36408 invoked by uid 500); 23 Mar 2006 17:26:45 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 36393 invoked by uid 99); 23 Mar 2006 17:26:44 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Mar 2006 09:26:44 -0800 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_WHOIS,HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [216.136.173.57] (HELO smtp013.mail.yahoo.com) (216.136.173.57) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 23 Mar 2006 09:26:41 -0800 Received: (qmail 90113 invoked from network); 23 Mar 2006 17:26:20 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:Mime-Version:In-Reply-To:References:Content-Type:Message-Id:From:Subject:Date:To:X-Mailer; b=aRmctLEs9brOive5BDs6R62kEe3ejQ31M6oT/8CVJ0M1JCCy32B7ROZ2KDm4OktKp8X1TMEthsY4MROiHHHQ6xD6CRyWQvm4kbJV0s6BYfgwKADGawVWW6DiO1t4GAs/Szuy5FbjqOFJwiTOgzTPlLaGMbsi778un1nWVt7B6hQ= ; Received: from unknown (HELO ?192.168.1.5?) (david?jencks@66.93.38.137 with plain) by smtp013.mail.yahoo.com with SMTP; 23 Mar 2006 17:26:17 -0000 Mime-Version: 1.0 (Apple Message framework v746.2) In-Reply-To: <785A212E11918F449D1318C61B7A9B0E2B956E@cs-mailsvr.Virtusa.com> References: <785A212E11918F449D1318C61B7A9B0E2B956E@cs-mailsvr.Virtusa.com> Content-Type: multipart/alternative; boundary=Apple-Mail-1--528665509 Message-Id: <413579AC-79BF-4A83-8B89-AD77B75A42FB@yahoo.com> From: David Jencks Subject: Re: how to lookup a datasource from standalone java class Date: Thu, 23 Mar 2006 09:26:15 -0800 To: user@geronimo.apache.org X-Mailer: Apple Mail (2.746.2) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --Apple-Mail-1--528665509 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252; delsp=yes; format=flowed On Mar 23, 2006, at 6:05 AM, Siraj Mohamed wrote: > Hi All, > > > > I have created a data source and I tried to look up this from a =20 > standalone java class like this: > > > > try { > > Context jndiCntx =3D new InitialContext(); > > DataSource ds =3D (DataSource) jndiCntx.lookup("MyDatasource"); > > DataSource ds =3D (DataSource)obj; > > System.out.println("Connected =85.. "); > > return ds.getConnection(); > > } catch (Exception e) { > > e.printStackTrace(); > > } This won't work. Datasources deployed in geronimo are only available =20= in the j2ee environment in which they are deployed: either a server =20 or a j2ee app client in which you have deployed a datasource. There =20 is no way to access one from a different vm. Furthermore you can only use jndi to look one up in a thread that has =20= gone through a j2ee component such as an ejb or web app (or j2ee app =20 client). thanks david jencks > > > My class path has jndi.properties for Geronimo and I am getting =20 > following exception in my class. > > > > javax.naming.NameNotFoundException: /MyDatasource not found > > at org.openejb.client.JNDIContext.lookup=20 > (JNDIContext.java:257) > > at javax.naming.InitialContext.lookup=20 > (InitialContext.java:361) > > > > And this is the server side error: > > ERROR [ContainerIndex] contianerId is not a valid ObjectName: =20 > MyDatasource > > > > But I was able to lookup this data source from an entity bean like: > > new InitialContext().lookup("java:comp/env/jdbc/MyExampleDS "); > > > > This the openejb-jar.xml for my EJB > > > > > xmlns=3D"http://www.openejb.org/xml/ns/openejb-jar" > > xmlns:naming=3D"http://geronimo.apache.org/xml/ns/naming" > > xmlns:security=3D"http://geronimo.apache.org/xml/ns/security" > > xmlns:sys=3D"http://geronimo.apache.org/xml/ns/deployment" > > configId=3D"geronimo/CustomerEJB/1.0/car" > > parentId=3D"geronimo/system-database/1.0/car"> > > > > > > CustomerEJB > > CustomerHomeRemote > > CustomerRemote > > > > jdbc/MyExampleDS > > MyDatasource > > > > > > > > > > > > Could any one explain me the differences between two attempts? > > > > This is the data source deployment plan. > > > > > > > > > configId=3D"MyDatasource" > > parentId=3D"geronimo/j2ee-server/1.0/car"> > > > > mysql > > mysql > > 3.0 > > > > > > > > > > > > javax.sql.DataSource > > > > > > MyDatasource > > > > xmeta > > > > > > xmeta > > > > > > com.mysql.jdbc.Driver > > > > > > jdbc:mysql://localhost:3306/xmeta > > > > > > false > > > > > > org.tranql.connector.NoExceptionsAreFatalSorter > > > > > > > > > > > > 10 > > 1 > > > > 5000 > > > > > > 30 > > > > > > > > > > > > > > > > > > > > > > > > Thanks, > > Siraj > > --Apple-Mail-1--528665509 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=WINDOWS-1252
On Mar 23, 2006, = at 6:05 AM, Siraj Mohamed wrote:

Hi All,

I have created a data source and I = tried to look up this from a standalone java class like this:=A0

try = {=A0Context jndiCntx =3D new (

= =3D (DataSource) (

= =3D=A0 ;

=A0("Connected = =85.. ");

=

} catch (Exception e) {=A0(

This won't work.=A0 Datasources = deployed in geronimo are only available in the j2ee environment in which = they are deployed: either a server or a j2ee app client in which you = have deployed a datasource.=A0 There is no way to access one from a = different vm.=A0=A0

Furthermore you can only = use jndi to look one up in a thread that has gone through a j2ee = component such as an ejb or web app (or j2ee app client).

thanks
david = jencks

=A0

My class = path has for = Geronimo and I am getting following exception in my class.=A0

: = / not = found

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = (JNDIContext.java:257)=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = (InitialContext.java:361)=A0

And this is = the server side error:

ERROR = [] = is not a = valid : =

But I was able to lookup this data = source from an entity bean like:

=A0new = ");

This the openejb-jar.xml for my EJB

<openejb-jar

=A0=A0=A0 xmlns=3D"http://www.openejb.org/= xml/ns/openejb-jar"

=A0=A0=A0 xmlns:naming=3D"http://geronimo.apache.o= rg/xml/ns/naming"

=A0=A0=A0 xmlns:security=3D"http://geronimo.apache= .org/xml/ns/security"

=A0=A0=A0 xmlns:sys=3D"http://geronimo.apac= he.org/xml/ns/deployment"

=A0=A0=A0 configId=3D"geronimo/CustomerEJB/1.0/car"=A0=A0=A0 parentId<enterprise-beans>

=A0=A0=A0 <entity>

=A0=A0=A0=A0=A0=A0=A0 <ejb-name>=A0=A0=A0=A0=A0=A0=A0 = <jndi-name>CustomerHomeRemote</jndi

=A0=A0=A0=A0=A0= =A0=A0 -name>CustomerRemote</local-jndi

=A0=A0=A0=A0=A0= =A0=A0

=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 jdbc/MyExampleDS</ref-name>

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = <resource-link>MyDatasource</resource-link>=A0=A0=A0=A0=A0=A0=A0 = </resource-ref>=A0=A0=A0 </entity>

=A0

Could any = one explain me the differences between two attempts?=A0

This is the = data source deployment plan.

version=3D"1.0"?>=A0

xmlns=3D"http://geronimo.= apache.org/xml/ns/j2ee/connector"

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = configId=3D"MyDatasource"

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =

=A0=A0=A0 = =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 <groupId>mysql</groupId>

=A0=A0=A0 <>mysql</artifactId>

=A0=A0=A0 <version>3.0</version>=A0=A0=A0 =A0=A0=A0=A0</dependency><

=A0 = <outbound-

=A0=A0=A0 = <

=A0=A0=A0=A0=A0= <-interface>

=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0 = </

=A0=A0=A0=A0=A0 <-instance>

=A0=A0=A0=A0=A0=A0=A0 <name>MyDatasource</name>

=A0=A0=A0=A0=A0=A0=A0 <config-property-setting name=3D"UserName">

=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0 = </config-property-setting>=A0=A0=A0=A0=A0=A0=A0 = <config-property-setting name=3D"Password">=A0=A0=A0=A0=A0=A0=A0=A0=A0 = xmeta=A0=A0=A0=A0=A0=A0=A0 = </config-property-setting>=A0=A0=A0=A0=A0=A0=A0 = <config-property-setting name=3D"Driver">=A0=A0=A0=A0=A0=A0=A0=A0=A0 = =A0=A0=A0=A0=A0=A0=A0 = </config-property-setting>=A0=A0=A0=A0=A0=A0=A0 = <config-property-setting name=3D"ConnectionURL">

=A0=A0=A0=A0=A0=A0=A0=A0=A0 jdbc:mysql://localhost:3306/xmeta=A0=A0=A0=A0=A0=A0=A0 = </config-property-setting>=A0=A0=A0=A0=A0=A0=A0 = <config-property-setting name=3D"

=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 false

=A0=A0=A0=A0=A0=A0=A0 </config-property-setting>=A0=A0=A0=A0=A0=A0=A0 = <config-property-setting name=3D"

=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0 = </config-property-setting>=A0

=A0=A0=A0=A0=A0=A0=A0 <

=A0=A0=A0=A0=A0= =A0=A0=A0=A0

=A0=A0=A0=A0=A0=A0=A0=A0=A0 <single-pool>

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =

=A0=A0=A0=A0 =A0=A0=A0=A0=A0=A0=A0=A0<blocking-timeout-milliseconds>

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = 5000=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = <

30

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 = <match-one/>=A0=A0=A0=A0=A0=A0=A0=A0=A0 = </single-pool>=A0=A0=A0=A0=A0=A0=A0 = </

=A0=A0=A0=A0=A0= </

=A0=A0=A0 </connection-definition>=A0 </outbound-resourceadapter>

</connector>=A0

Thanks,Siraj



<= /HTML>= --Apple-Mail-1--528665509--