欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

connection

程序员文章站 2022-05-13 17:42:39
...

JDBC中Class12.jar和ojdbc14.jar的区别
文章分类:数据库
最近在项目中仅常遇到,在这家客户那里邮件发送没问题,可是跑到另外一家客户那里缺发不出去,觉得很奇怪,通过一番折腾之后,把问题落在了Oracle JDBC Driver上,因为在客户现场,用的oracle版本不统一,有些客户使用的是oracle9i,有些使用的是Oracle10g,但是项目中同意使用了ojdbc14.jar做为驱动,那当然就有问题了,以下列出在2个驱动之间的区别:

    1.oracle10g中将中文字符解析为3个字节,oracle9i中保留为2个字节,在插入时常常会因为这个问题而造成数据插入失败、超常
    2.在处理大字符集的时候,同样存在字符限制,class12只能支持到3000左右吧,ojdbc14可以支持到更长
============================================================================================================================

 

package com.bonson.common.tool;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import com.bonson.common.log4j.Log4jInit;

/**
 * 数据库操作类
 *
 * @classname DataBaseConn
 *
 * @author linzhou
 *
 * @version v1.0
 *
 * @date 2010-4-7
 *
 * @copyrigth bonson
 */
public class DataBaseConn
{

 private static final long serialVersionUID = 8280428586539580616L;
 
 /**
  * 创建数据库连接
  *
  * @return Connection对象
  */
 public Connection getConn()
 {  
  Connection conn = null;
  try
  {
   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
   //Class.forName("oracle.jdbc.driver.OracleDriver");
   conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.12.208:1521:orcltech","fjcars","fjcars09");
  }
  catch (Exception e)
  {
   Log4jInit.logger(DataBaseConn.this).error("getConn:" + e.toString());
   this.closeConn(conn, null, null, null);
  }   
  return conn;
 }
 /**
  * 关闭连接
  *
  * @param conn
  *    Connection对象
  * @param stmt
  *    Statement对象
  * @param rs
  *    ResultSet对象
  * @param cs
  *    CallableStatement对象
  */
 public void closeConn(Connection conn, Statement stmt, ResultSet rs, CallableStatement cs)
 {
  try
  {
   if (rs != null)
   {
    rs.close();
    rs = null;
   }
   if (stmt != null)
   {
    stmt.close();
    stmt = null;
   }
   if (cs != null)
   {
    cs.close();
    cs = null;
   }
   if (conn != null)
   {
    conn.close();
    conn = null;
   }
  }
  catch (Exception e)
  {
   Log4jInit.logger(DataBaseConn.this).error("closeConn:" + e.toString());
  }
 }
}

 

 

 

 

 

配置文件

#oracle
jdbc.driverClassName=oracle.jdbc.OracleDriver
#jdbc.url=jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.46.51.196)(PORT = 1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 10.46.51.198)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = acsdb)(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5))))
#jdbc.username=wcity
#jdbc.password=wcity#wcity

jdbc.url=jdbc:oracle:thin:@172.16.16.52:1521:wcitydb
jdbc.username=wcity2
jdbc.password=wcity2

cpool.checkoutTimeout=5000
cpool.minPoolSize=20
cpool.maxPoolSize=50
cpool.maxIdleTime=7200
cpool.maxIdleTimeExcessConnections=1800
cpool.acquireIncrement=10