cesar
cesar

Reputation: 9064

How do I use JDBC's data source?

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?

Upvotes: 1

Views: 527

Answers (1)

duffymo
duffymo

Reputation: 308763

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.

Upvotes: 2

Related Questions