• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database connection from Java application

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
get schwifty. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic