Connection between J2EE applications and Oracle databases

Source: Internet
Author: User
In J2EE application development, establishing a connection between an application and a database is a common problem. Here I will talk about connecting to the Oracle database through OCI, thin, and JdbcOdbc in local applications, configure the Oracle database connection pool in iPlanet Application Server 6.5 and Sun ONE Application Server 7 and how to obtain the connection from the connection pool in the Application.
1. Obtain the Oracle database connection through JDBC locally
You can use JDBC to obtain Oracle database connections in three ways: OCI, thin, and JdbcOdbc. The OCI method depends on the local dynamic link library. This method can be used if the Oracle database client is installed locally. The thin method is a java-only database connection method; the JdbcOdbc bridge mode depends on the configuration of the local ODBC database source, which is generally not used.
1. OCI mode
First, install the Oracle client locally. After installation, find... The/jdbc/lib/classes12.zip file sets the path of classes12.zip in the environment variable classpath.
Then, use the following database connection classes to locally obtain the Oracle database connection through OCI.
/**
* Obtain a local database connection
*/
Package com. j2ee. db;
Import java. util .*;
Import java. SQL .*;
Import javax. SQL .*;
Import java. io .*;
Import oracle. jdbc. driver .*;
Import javax. naming .*;
/**
* Obtain the Oracle database connection through OCI
*/
Public class DbConnection
{
Final static String sDBDriver = "oracle. jdbc. driver. OracleDriver ";
Final static String sConnStr = "jdbc: oracle: oci8: sr/sr @ ora199 ";

/**
*
*/
Public DbConnection ()
{
}

/**
* Obtain the Oracle database connection
*/
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 username and password of the Oracle user, and "ora199" is the database service name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.