views:

41

answers:

1

I've tried researching how to use the DataSource method of connecting to a database but never could find out how. I know that a DataSource is first configured and registered to JNDI in an application that is separate from the user application, and all the user application will do is retrieve it using JNDI. What I don't understand is where the DataSource is configured. Is it automatically registered when I turn on MySQL, do I need to download another application to register it, or do I make a new class that will do that for me?

+2  A: 

You usually have a Java EE app server like Glassfish, WebLogic, JBOSS, Tomcat, or Jetty have a JNDI provider that you should be using for the lookup.

Here's how you do it with Oracle.

Here's how you do it with MySQL.

The JDK 6 javadocs say that a basic DataSource can supply a connection if your driver has such an implementation. I would recommend looking at the Connector-J docs to see if you can do it without JNDI lookup services.

duffymo
do you really need an EE app to register it?
anonymous
You need a JNDI naming service to do the lookup.
duffymo
so... you examples of the naming service are stuff like servers?
anonymous