In the Java EE application development, the application and the database connection establishment is one of the problems that we often encounter. Here I talk about connecting Oracle databases through OCI, thin, and jdbcodbc bridges in local applications, iplanet Application Server 6.5 and Sun one application server 7 The configuration of the Oracle database connection pool and how to obtain a connection from the connection pool in the application.
First, local access to Oracle database connections via JDBC
Oracle database connections are available through JDBC in three ways: OCI, thin, and Jdbcodbc bridge mode. The OCI approach relies on a local dynamic-link library, which can be used if Oracle database clients are installed locally, whereas thin is a pure Java database connection, and Jdbcodbc Bridge relies on the configuration of local ODBC database sources, which is generally not used.
1, OCI Way
To install the Oracle client locally first, after installation, you can find the .../jdbc/lib/classes12.zip file in the installation path, where we set the Classes12.zip path in the environment variable CLASSPATH.
The Oracle database connection is then OCI locally through the following database connection classes.
/**
* 在本地获得数据库连接
*/
package com.j2ee.db;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
import javax.naming.*;
/**
* 通过OCI方式获得Oracle数据库连接
*/
public class DbConnection
{
final static String sDBDriver = "oracle.jdbc.driver.OracleDriver";
final static String sConnStr = "jdbc:oracle:oci8:sr/sr@ora199";
/**
*
*/
public DbConnection()
{
}
/**
* 获得Oracle数据库连接
*/
public java.sql.Connection connectDbByOci()
{
java.sql.Connection conn=null;
try
{
Class.forName(sDBDriver);
conn = DriverManager.getConnection(sConnStr);
}
catch (Exception e)
{
System.out.println("ERROR:"+e.getMessage());
}
return conn;
}
}
In the connection string "jdbc:oracle:oci8:sr/sr@ora199", "SR/SR" is the user name and password for the Oracle user, and "ora199" is the database service name.