Get JDBC Connection

To get JDBC connection, normally there are two ways: 1. database driver manager 2. use data source

1. Using Database Driver Manager

The first approach includes the following steps
1. Register the database driver
2. Using DriverManager to get a connection to the database
3. query/update database
3. close other resources and close the connection

To get connection to different databases, the values will be different:

MySQL

Oracle

PostgresSQL

DB2

2. Using DataSource

If JNDI and the DataSource are available, DataSource interface shall be used to get a Connection. Normally, an application server or a servlet container can support JNDI, DataSource configuration and connection pool support.

Example:

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

2 thoughts on “Get JDBC Connection

  1. Pingback: JDBC by Examples

  2. Pingback: JDBC by Examples

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">