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"
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.
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.