views:

53

answers:

5

Hi

The title pretty much says it all, but here's some background.

We have a database configured in glassfish accessed by a website deployed on glassfish, we also access the database from an external java application, it occurred to me that this could be somewhat inefficient since we open quite a few connections to the database from our external app. So I was wondering if we could somehow access he database through glassfish's connection pool?

Thanks in advance.

Piers

A: 

That would only be possible if your external application was running in the same VM as glassfish. The word "external" says: Nope, not possible.

Note that databases are designed to handle lots of connections. That's one of the main reasons why they exist: To allow several programs at once to work on the same data.

Aaron Digulla
A: 

I don't think you can access the pool, if your program does not run on glassfish. A few connections to the database shouldn't matter too much, at least if the aren't created and destroyed very often. You could build a pool in your external application as well, if that is the case.

hackbert
Just thinking it would be nice to use an already built and tested pool which centralizes access. Oh well -_-
PiersyP
How about using ConnectionPoolDataSource (part of jdbc 2.0)? Does your driver provide an implementation?
hackbert
A: 

You'll have to try this.

http://javahowto.blogspot.com/2006/08/access-glassfish-datasource-remotely.html suggests it is possible to look up the connection pool via JNDI from a standalone client. An actual client code example is given at http://javahowto.blogspot.com/2006/08/access-jboss-datasource-remotely-from.html#client

JoseK
Thanks Jose, this is what I was looking for :D
PiersyP
Found some more info on the subject, here's a guide to remotely accessing a database configured with glassfish using the java persistence api.http://technology.amis.nl/blog/962/getting-started-with-ejb-30-persistence-out-of-container-using-the-reference-implementation-glassfish
PiersyP
A: 

Well I'm answering my own question, and it's not a brilliant answer but it does sort of fulfil the requirements of my question.

What you can do is connect to an EJB from an external java application, if the bean provides access to your database then by using it you will be making use of the connection pooling provided by glassfish.

You can find info on how to do this

here - https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

In terms of efficiency I'm not sure if this is a good idea since it may put excess strain on your web application, in my initial idea I was thinking to bypass the webapp completely and communicate directly with glassfish, any comments on this would be appreciated.

PiersyP
A: 

Another option is to add a web service to your Glassfish data access object.

You could then access the database with SOAP or REST calls.

Gilbert Le Blanc