Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking Data Source Remotely

 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,

Can we use Data Source of an App Server from a remote machine? actually i have to make a database call from my application which resides out side the App Server, and i dont want to take the pain of writing connection pool logic for this program, i was just wondering if i can use the DataSource of the DataBase connection created in the AppServer running on same machine.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't access a DataSource defined in a container directly from code running outside it. What you can do is write a simple EJB which just has methods to run SQL though. Or write a service method for this DB call you need to make.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand what is the problem. If you need a DataSource, you get it from the app server's JNDI tree. When you instantiate InitialContext, you need to ensure that its environment is initialized with properties defined in the environment parameter passed to the constructor. You have to do this as your client is outside the server.

Once you've got the InitialContext, you can then get a JDBC Connection and create a Statement from that Connection.

You do not deal with connection pooling, this is done on the server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic