File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Looking up DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Looking up DataSource" Watch "Looking up DataSource" New topic
Author

Looking up DataSource

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I couldn't get the connection object to a Datasource configured in the App Server in stand alone client program.

But the following code works well in a EJB that is deployed in that server ..

Can any one tell me the reason for this .

Srini
[ October 16, 2004: Message edited by: srini vasan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

the problem might be related in looking up initial context ...
are you able to get intialContext ?? try to print intialConext etc
[ October 23, 2004: Message edited by: Shailesh Chandra ]

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

try (DataSource)ic.lookup("java:comp/env/jdbc/testDS");


Groovy
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Shailesh Chandra:
the problem might be related in looking up initial context ...
are you able to get indiaContext ?? try to print intialConext etc

I'll try that
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Pradeep Bhat:
try (DataSource)ic.lookup("java:comp/env/jdbc/testDS");


Whats the difference b/w ic.lookup("java:comp/env/jdbc/testDS") and
ic.lookup("jdbc/testDS")

Can you explain me ?

Srini
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by srini vasan:


Whats the difference b/w ic.lookup("java:comp/env/jdbc/testDS") and
ic.lookup("jdbc/testDS")

Can you explain me ?

Srini


Both is not defference.

Because default of jndi is "java:comp/env" is default place to start lookup in Directory.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by srini vasan:
I couldn't get the connection object to a Datasource configured in the App Server in stand alone client program.

But the following code works well in a EJB that is deployed in that server ..

Can any one tell me the reason for this .

Srini

[ October 16, 2004: Message edited by: srini vasan ]


Your error is NamingNotFoundException or NullPointerException ??

If NamingNotFoundException, you jndi or DD is wrong in configuration.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
I'm getting this exception :

NamingException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
This is the Source code of client


[ October 27, 2004: Message edited by: srini vasan ]
nilesh Katakkar
Ranch Hand

Joined: Oct 27, 2004
Posts: 35
Since you are using a standalone Java Client Application, it's probably running outside the JVM of your appserver. The url for lookup "java:comp/env/<beanJNDIName>", is the J2EE specification for looking EJB's (or other resources) INSIDE the same environment, not outside of the environment. You java client app has no idea about java:comp

Try giving entire url for lookup e.g.

context.lookup("<protocol>://<host>:<port>/<resourceName>")

On my box I have a DataSource registered in weblogic JNDI Namespace under context jdbc/Oracle_sid. From standalone java app I look up datasource as

DataSource ds = (DataSource)context.lookup("t3://localhost:7001/jdbc/Oracle_sid");

Connection connection = ds.getConnection();


nilesh<br />neilindallas@hotmail.com
Murugan Patham
Greenhorn

Joined: Oct 16, 2004
Posts: 20
Is it not the InitialContext got from getIntialContext Methood using the URL will tell where to look. Do we need to give full URL in the lookup?
nilesh Katakkar
Ranch Hand

Joined: Oct 27, 2004
Posts: 35
Murugham Patham
<quote>
Is it not the InitialContext got from getIntialContext Methood using the URL will tell where to look. Do we need to give full URL in the lookup?
</quote>

Yeah.. sorry.
Murugham you are right.You don't have to give full URL in the lookup.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking up DataSource