Java Database Connection Pool Oracle Edition

Source: Internet
Author: User
Tags connection pooling

You should first join the configuration file for connection pooling and database connections:
Database Connection pack: Ojdbc6.jar
Database Connection Pool Package: Commons-pool2-2.2.jar
Commons-dbcp2-2.0.jar
Database connection configuration file: Config.properties
Connect using connection pooling Be sure not to forget to shut it down or it'll be unlucky.

The writing of DBHelper

Import java.io.IOException;
Import Java.io.InputStream;
Import java.sql.Connection;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.util.Properties;

Import Org.apache.commons.dbcp2.BasicDataSource;

public class DBHelper {
private static Basicdatasource ds = new Basicdatasource ();

static {
InputStream is = Dbhelper.class
. getResourceAsStream ("config.properties");
Properties prop = new properties ();
try {
Prop.load (IS);
Ds.setdriverclassname (Prop.getproperty ("Driver"));
Ds.seturl (prop.getproperty ("url"));
Ds.setusername (Prop.getproperty ("username"));
Ds.setpassword (Prop.getproperty ("password"));
System.out.println (Ds.getdriverclassname () + Ds.geturl ());
} catch (IOException e) {
E.printstacktrace ();
} finally {
try {
if (is = null)
Is.close ();
} catch (IOException e) {
E.printstacktrace ();
}
}
}

public static Connection getconnection () throws SQLException {
return Ds.getconnection ();
}

public static void Close (ResultSet rs, PreparedStatement PS, Connection conn) {
try {
if (rs! = null)
Rs.close ();
if (PS! = null)
Ps.close ();
IF (conn! = null)
Conn.close ();
} catch (SQLException e) {
E.printstacktrace ();
}
}

}


Config.properties File configuration:

Driver=oracle.jdbc.driver.oracledriver
Url=jdbc\:oracle\:thin\:@10.141.42.119\:1521\:orcl
Username=hdid01
Password=hdid01

Database connection Pool Oracle Version "Name=" image_operate_7261294294145390 "alt=" Java database connection Pool Oracle Edition "src=" http ://s3.sinaimg.cn/middle/5ff02a9ft99274e5cac92&690 "width=" 540 "height=" 217 ">

Placement of two files:

Database connection Pool Oracle Edition "alt=" Java database connection pool Oracle Version "src=" http://s9.sinaimg.cn/middle/ 5ff02a9ft99275363f018&690 "width=" 235 "height=" >

So you can use it, or you can config.properties it somewhere else and change it.

InputStream is = Dbhelper.class
. getResourceAsStream ("config.properties");

Find the path to the file to modify it.

Related Article

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.