Java項目中使用 proxool__Java

來源:互聯網
上載者:User

在網上找到的proxool 入門執行個體 都是在web項目中使用的  

下面這個例子是單純的java項目中運用proxool。

總結一下,其實也很簡單就是將 proxool.xml  載入進來 的方法的不一樣  


需要的jar檔案有:

classes12-10.0.2.jar

commons-logging-1.0.4.jar

proxool-0.9.1.jar

proxool-cglib-0.9.1.jar


相關資源下載:http://download.csdn.net/detail/xswd169/6366947


代碼如下:


TestProxool

package com.leader.proxool;import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;/** * Created by IntelliJ IDEA. *  * @author leizhimin 2009-10-10 17:59:47 */public class TestProxool {public static String dburl = "jdbc:oracle:thin:@192.168.104.192:1521:tim";public static String user = "tim";public static String password = "tim_8968888";/** * JDBC方式測試 *  * @throws Exception */public static void test1() throws Exception {String testsql = "select * from village t where lastid = 346";// 1:註冊驅動類Class.forName("oracle.jdbc.driver.OracleDriver");// 2:建立資料庫連接Connection conn = DriverManager.getConnection(dburl, user, password);// 3:建立執行SQL的對象Statement stmt = conn.createStatement();// 4:執行SQL,並擷取返回結果ResultSet rs = stmt.executeQuery(testsql);// 5:處理返回結果,此處列印查詢結果while (rs.next()) {System.out.print(rs.getLong("id") + "\t");System.out.print(rs.getString("name") + "\t");System.out.println();}// 6:關閉資料庫連接conn.close();}/** * proxool方式測試 *  * @throws Exception */public static void test2() throws Exception {// Java應用中先要載入設定檔,否則誰知道你配置給誰用的JAXPConfigurator.configure("E:\\EclipseNew\\eclipse\\workSpace\\Proxool\\proxool.xml", false);String testsql = "select * from dest_poi";// 1:註冊驅動類,這次這個驅動已經不是Oracle的驅動了,是Proxool專用的驅動Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");// 2:建立資料庫連接,這個參數是一個字串,是資料來源的別名,在設定檔中配置的timalias,參數格式為:proxool.資料來源的別名Connection conn = DriverManager.getConnection("proxool.First");// 3:建立執行SQL的對象Statement stmt = conn.createStatement();// 4:執行SQL,並擷取返回結果ResultSet rs = stmt.executeQuery(testsql);// 5:處理返回結果,此處列印查詢結果while (rs.next()) {System.out.print(rs.getLong("id") + "\t");System.out.print(rs.getString("dest_name") + "\t");System.out.println();}// 6:關閉資料庫連接conn.close();}/** * 測試 * @param args * @throws Exception */public static void main(String[] args) throws Exception {test2();}}

proxool.xml 

<?xml version="1.0" encoding="UTF-8"?><something-else-entirely>        <proxool>                <alias>First</alias>                <!--資料來源的別名-->              <driver-url>jdbc:oracle:thin:@10.10.10.4:1521:orcl</driver-url>                <!--url串連串-->                <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>                <!--驅動類-->                <driver-properties>                <!--使用者名稱-->                <property name="user" value="tcar1" /><!--密碼--><property name="password" value="tcar_cityonmap2012" />                </driver-properties>                <!--最大串連數(預設5個),超過了這個串連數,再有請求時,就排在隊列中等候,最大的等待請求數由maximum-new-connections決定 -->                <maximum-connection-count>100</maximum-connection-count>                <!--最小串連數(預設2個)-->                <minimum-connection-count>10</minimum-connection-count>                <!--proxool自動偵察各個串連狀態的時間間隔(毫秒),偵察到閒置串連就馬上回收,逾時的銷毀 預設30秒-->                <house-keeping-sleep-time>90000</house-keeping-sleep-time>                <!--沒有空閑串連可以分配而在隊列中等候的最大請求數,超過這個請求數的使用者串連就不會被接受-->                <maximum-new-connections>10</maximum-new-connections>                <!--最少保持的空閑串連數(預設2個)-->                <prototype-count>5</prototype-count>                <!--在使用之前測試-->                <test-before-use>true</test-before-use>                <!--用於保持串連的測試語句 -->                <house-keeping-test-sql>select sysdate from dual</house-keeping-test-sql>        </proxool></something-else-entirely>





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.