This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Database connection from Java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Database connection from Java application" Watch "Database connection from Java application" New topic
Author

Database connection from Java application

Tom Raj
Greenhorn

Joined: Mar 03, 2005
Posts: 11
Hi all,
I have a simple application. I'm trying to connect to my udb database thru the datasource defined on my local websphere server. The code is below. Initially I was getting a ClasscastException at the line 'ds = (DataSource) obj' . After several trials I included the database implementation jars in the websphere directory in the java app's classpath and it worked.

My question here is does my java application go to my server for getting the connection or after getting the datasource instance, the connection happens locally? To test this, I terminated my server after getting the datasource reference by lookup (my java app in debug mode) and then executed the ds.getconnection(). It worked and so I think the connection is obtained locally. So does this connection be in a pool??

Can somebody elaborate what is happening here??


Properties props = new Properties();
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
DAOConstants.WS_INITIAL_CTX_FACTORY);
props.put(javax.naming.Context.PROVIDER_URL,"iiop://localhost:2809/");

DataSource ds = null;
Context context = new InitialContext(props);

Object obj = context.lookup("jdbc/CustDataSource");
ds = (DataSource) obj;
dBconn =ds.getConnection(DAOConstants.DB_USER_ID,DAOConstants.DB_USER_PWD);
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Hello Tom-

On your way in you may have missed that JavaRanch has a policy on display names, and yours does not comply with it - please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.


Ping & DNS - my free Android networking tools app
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

Tom,
Thanks for updating your display name.


Yes, the datasource is likely to be pooling connections. You can verify this by checking your datasource configuration on the server.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
wood burning stoves
 
subject: Database connection from Java application
 
Similar Threads
whether connection pool will available at the time of starting the server
Connection pool with multiple users
connecting to Data Base
Lookup problem for StandaloneApplication with Websphere 6.
JNDI Lookup from Java Client not working