JDBC Resources and Connection Pool : Explain

JDBC Resources

A JDBC resource (data source) provides applications with a means of connecting to a database. Typically, the administrator creates a JDBC resource for each database accessed by the applications deployed in a domain. (However, more than one JDBC resource can be created for a database.)

 

JDBC Resources

To store, organize, and retrieve data, most applications use relational databases. J2EE applications access relational databases through the JDBC API.

To create a JDBC resource, specify a unique JNDI name that identifies the resource. (See the section JNDI Names and Resources.) Expect to find the JNDI name of a JDBC resource in java:comp/env/jdbc subcontext. For example, the JNDI name for the resource of a payroll database could be java:comp/env/jdbc/payrolldb. Because all resource JNDI names are in the java:comp/env subcontext, when specifying the JNDI name of a JDBC resource in the Admin Console, enter only jdbc/name. For example, for a payroll database specify jdbc/payrolldb.

JDBC Connection Pools

To create a JDBC resource, specify the connection pool with which it is associated. Multiple JDBC resources can specify a single connection pool.

A JDBC connection pool is a group of reusable connections for a particular database. Because creating each new physical connection is time consuming, the server maintains a pool of available connections to increase performance. When an application requests a connection, it obtains one from the pool. When an application closes a connection, the connection is returned to the pool.

The properties of connection pools can vary with different database vendors. Some common properties are the database’s name (URL), user name, and password.

How JDBC Resources and Connection Pools Work Together

To store, organize, and retrieve data, most applications use relational databases. Java EE applications access relational databases through the JDBC API. Before an application can access a database, it must get a connection.

At runtime, here’s what happens when an application connects to a database:

  1. The application gets the JDBC resource (data source) associated with the database by making a call through the JNDI API.

    Given the resource’s JNDI name, the naming and directory service locates the JDBC resource. Each JDBC resource specifies a connection pool.

  2. Via the JDBC resource, the application gets a database connection.

    Behind the scenes, the application server retrieves a physical connection from the connection pool that corresponds to the database. The pool defines connection attributes such as the database name (URL), user name, and password.

  3. Now that it’s connected to the database, the application can read, modify, and add data to the database.

    The applications access the database by making calls to the JDBC API. The JDBC driver translates the application’s JDBC calls into the protocol of the database server.

  4. When it’s finished accessing the database, the application closes the connection.

    The application server returns the connection to the connection pool. Once it’s back in the pool, the connection is available for the next application.

    Sun Java System JDBC Driver for Oracle 8.1.7 and 9.x Databases

    The JAR files for this driver are smbase.jar, smoracle.jar, and smutil.jar. Configure the connection pool using the following settings:

    • Name: Use this name when you configure the JDBC resource later.

    • Resource Type: Specify the appropriate value.

    • Database Vendor: Oracle

    • DataSource Classname: com.sun.sql.jdbcx.oracle.OracleDataSource

    • Properties:

      • serverName – Specify the host name or IP address of the database server.

      • portNumber – Specify the port number of the database server.

      • SID – Set as appropriate.

      • user – Set as appropriate.

      • password – Set as appropriate.

    • URL: jdbc:sun:oracle://serverName[:portNumber][;SID=databaseName]

    Sun Java System JDBC Driver for Microsoft SQL Server Databases

    The JAR files for this driver are smbase.jar, smsqlserver.jar, and smutil.jar. Configure the connection pool using the following settings:

    • Name: Use this name when you configure the JDBC resource later.

    • Resource Type: Specify the appropriate value.

    • Database Vendor: mssql

    • DataSource Classname: com.sun.sql.jdbcx.sqlserver.SQLServerDataSource

    • Properties:

      • serverName – Specify the host name or IP address and the port of the database server.

      • portNumber – Specify the port number of the database server.

      • user – Set as appropriate.

      • password – Set as appropriate.

      • selectMethod – Set to cursor.

    • URL: jdbc:sun:sqlserver://serverName[:portNumber]

Advertisements

8 Responses

  1. Пора переименовать блог, присвоив название связанное с доменами 🙂 может хватит про них?

  2. Что-то такое слышал, но не так подробно, а откуда материал брали?

  3. Спасибо за статью оказалась очень полезной.

  4. Подойдя к второму обзацу необходимо будет побороть в себе желание его пропустить

  5. Hey, its been long since you posted here and was wondering if you still ok. We miss you and looking forward to seeing your post once again soon.

    Good luck

  6. Alert!: Oracle has announced their marquee event JavaOne and Oracle Develop 2012 being held in Hyderabad on 3-4 May. Registrations have also started (Link: http://www.oracle.com/javaone/in-en/index.html?pcode=WWMK11024795MPP084&src=7268797&Act=155 ).

  7. […] JDBC Resources and Connection Pool : Explain | Think Tank – The JAR files for this driver are smbase.jar, smoracle.jar, and smutil.jar. Configure the connection pool using the following settings: Name: Use this name when you configure the JDBC resource later. Resource Type: Specify the appropriate value. […]

  8. Annie,nAppreciate you can e-mail to me your e-copy in both English and Chinese version.nMany many thanks Click https://zhoutest.wordpress.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: