This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Invoking Data Source Remotely Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Invoking Data Source Remotely" Watch "Invoking Data Source Remotely" New topic

Invoking Data Source Remotely

Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
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.

Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
jQuery in Action, 2nd edition
subject: Invoking Data Source Remotely
Similar Threads
connecting to a remote PostgreSQL
Error while trying to configure the database
JApplet to access Database on server from client maschine
Best Practice: Where to put database in Web Application (Tomcat as one example)?
Problem in connecting to oracle 8i from java application