操屁眼的视频在线免费看,日本在线综合一区二区,久久在线观看免费视频,欧美日韩精品久久综

新聞資訊

    C3P0開源數據庫連接池的編寫源碼

    C3P0代碼分析

    class {

    // 第一步:靜態初始化快,加載配置文件

    e ds = null;

    {

    利用xml中的文件

    ds = new e();

    ds.("com.mysql.jdbc.");

    ds.("jdbc:mysql://:3306/jdbc");

    ds.("root");

    ds.("qiao");

    ds.(10);

    ds.(50);

    ds.(10);

    }

    () {

    ds.();

    }

    // 是把資源歸還到連接池中

    void ( con, st,

    rs) {

    if (rs != null) {

    try {

    rs.close();

    } catch ( e) {

    e.();

    }

    rs = null;

    }

    if (con != null) {

    try {

    con.close();

    } catch ( e) {

    e.();

    }

    con = null;

    }

    if (st != null) {

    try {

    st.close();

    } catch ( e) {

    // TODO Auto- catch block

    e.();

    }

    }

    }

    注:最核心的地方就是靜態初始化()里的東西,也就相當于是配置文件中的數值設置,即是數據庫的連接數據庫連接池代碼實現,我們完全可以把這么數據寫成一個xml文檔,用來存儲這些數據數據庫連接池代碼實現,xml文檔為c3p0-.xml

    "">com.mysql.jdbc.

    "">jdbc:mysql://:3306/jdbc

    "user">root

    "">qiao

    "">

    "">30000

    "riod">30

    "">10

    "">30

    "">100

    "">10

    "">200

    "mysql">

    "">com.mysql.jdbc.

    "">jdbc:mysql://:3306/jdbc

    "user">root

    "">qiao

    "">50

    "">100

    "">50

    "">1000

    所有上面的代碼可以寫為:

    class {

    // 第一步:靜態初始化塊,加載配置文件

    e ds = null;

    {

    //利用xml中的文件

    ds = new e("mysql");

    }

    () {

    ds.();

    }

    // 是把資源歸還到連接池中

    void ( con, st,

    rs) {

    if (rs != null) {

    try {

    rs.close();

    } catch ( e) {

    e.();

    }

    rs = null;

    }

    if (con != null) {

    try {

    con.close();

    } catch ( e) {

    e.();

    }

    con = null;

    }

    if (st != null) {

    try {

    st.close();

    } catch ( e) {

    // TODO Auto- catch block

    e.();

    }

    }

    }

    注:ds = new e("mysql");中的參數是xml文檔中的命名的name,也可以用默認的,如果沒有指定則為默認的。

網站首頁   |    關于我們   |    公司新聞   |    產品方案   |    用戶案例   |    售后服務   |    合作伙伴   |    人才招聘   |   

友情鏈接: 餐飲加盟

地址:北京市海淀區    電話:010-     郵箱:@126.com

備案號:冀ICP備2024067069號-3 北京科技有限公司版權所有