File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes DataSource.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "DataSource...." Watch "DataSource...." New topic


Suresh Selvaraj
Ranch Hand

Joined: Nov 14, 2000
Posts: 104
Hi All,
Can anyone explain me on what happens when we use the following.
For Example;
InitialContext icx = new InitialContext();
DataSource ds = (DataSource)icx.lookup(collo/apps);
I'd like to know how and where the "collo/apps" is registered.
Any example on how and where to register?
Suresh Selvaraj

Suresh Selvaraj, (author of JQuiz)<br />SCJP2<br /><a href="" target="_blank" rel="nofollow"></a>
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
Before you can "look up" an object, you must first bind the object to a context.
MyDataSource dataSource = new MyDataSource();
Contex c = new InitialContext();
context.bind( "collo/apps", dataSource);
In the above lines, we created a data source, which represents your connection pool, then we created an IntitialContext so we could "bind" the object to an alias -- in this case "collo/apps" -- using JNDI.
The data source is now available to anyone, even applications running on remote machines. It should matter to you "where" the object is stored, because it could be stored on a remote machine.
Hope that helps...
Naveen Kuppili

Joined: Oct 19, 2001
Posts: 24
It is actually better that you do this declaratively using the tool provided by your vendor rather than programmatically. For example with iPlanet, you can use "dsreg" to register a datasource. This way it is much easier to specify the driver details, max number of connections, etc.
Unless there is a strong reason to do it programmatically, this is the preferred way of registering a datasource.

[This message has been edited by Naveen Kuppili (edited November 27, 2001).]
Suresh Selvaraj
Ranch Hand

Joined: Nov 14, 2000
Posts: 104
Thanks SAF and Naveen.
I agree. Here's the link:
subject: DataSource....
It's not a secret anymore!