自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Oracle數(shù)據(jù)庫的密集型實際應(yīng)用程序的開發(fā)

數(shù)據(jù)庫 Oracle
以下的文章主要是介紹 UCP JDBC 連接池用到的HR/HR Oracle 數(shù)據(jù)庫的示例模式建立連接的實際操作方案的描述。以下就是正文的介紹。

我們都知道再開發(fā)Oracle數(shù)據(jù)庫的密集型實際應(yīng)用程序時,使用相關(guān)連接池而受益。之所以是因為這樣,我們才能夠重用連接,而不是在每次請求連接時都重新創(chuàng)建一個新連接。連接池節(jié)約了創(chuàng)建新數(shù)據(jù)庫連接所需的資源,并提高了應(yīng)用程序的性能,因為創(chuàng)建新連接始終是一個性能密集型操作。

 

Oracle Universal Connection Pool for JDBC 表示一個用于緩存 JDBC 連接的全功能實現(xiàn)。UCP 是一個非常有用的特性,它將使您可以重用連接對象,從而可以提高獲取連接過程的速度并節(jié)約打開新數(shù)據(jù)庫連接所需的資源。

假設(shè)您希望創(chuàng)建一個 UCP JDBC 連接池來重用到 HR/HR Oracle 數(shù)據(jù)庫示例模式的已建立連接。以下程序是一個 UCP JDBC 連接池實際運行的簡單示例,將向您展示如何完成此操作。您將首先創(chuàng)建一個支持池的數(shù)據(jù)源實例,然后設(shè)置連接和池的屬性。完成后,您將從池中借用一個連接,然后使用該連接與數(shù)據(jù)庫交互。***,您將關(guān)閉該連接,將其返回到池。

 

  1. import java.sql.*; import oracle.ucp.jdbc.PoolDataSourceFactory; 
    import oracle.ucp.jdbc.PoolDataSource; public class UcpConnection 
    { public static void main(String args[]) throws SQLException 
    { try { //Creating a pool-enabled data source PoolDataSource 
    pds 
    PoolDataSourceFactory.getPoolDataSource(); 
    //Setting connection properties of the data source pds.
    setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); 
    pds.setURL("jdbc:oracle:thin:@//localhost:1521/XE"); pds.setUser("hr"); 
    pds.setPassword("hr"); //Setting pool properties pds.setInitialPoolSize(5); 
    pds.setMinPoolSize(5); pds.setMaxPoolSize(10); 
    //Borrowing a connection fro th oo Connection 
    con = pds.getConnection();  
  2. ount(); System.out.println("\nAvailable connections: 
    " + avlConnCount); int 
    brwConnCount = pds.getBorrowedConnectionsCount(); 
    System.out.println("\nBorrowed connections: " + brwConnCount); 
    //Working with the connection Statement 
    stmt = conn.createStatement(); 
    ResultSet 
    rs = stmt.executeQuery("select user from dual"); 
    while(rs.next()) System.out.println("\nConnected as: "+rs.getString(1)); 
    rs.close(); //Returning the connection to the pool conn.close(); 
    conn=null
    System.out.println("\nConnection returned to the pool"); 
    //Checking the number of available and borrowed connections again 
    avlConnCount = 
    pds.getAvailableConnectionsCount(); 
    System.out.println("\nAvailable connections: " + avlConnCount); 
    brwConnCount = pds.getBorrowedConnectionsCount(); 
    System.out.println("\nBorrowed connections: " + brwConnCount); } 
    catch(SQLException e) 
    { System.out.println("\nAn SQL exception occurred : " + e.getMessage()); } } } 

 

 

這里值得注意的是關(guān)閉連接時的變化。以上程序的輸出闡釋了關(guān)閉從 UCP JDBC 連接池中借用的連接將使該連接返回到池,以供下一次連接請求使用。

 

該應(yīng)用程序的輸出應(yīng)如下所示:

 

  1. Connection borrowed from the poolAvailable connections: 
    4Borrowed connections: 1Connected as: HRConnection returned 
    to the poolAvailable connections: 5Borrowed connections: 0 

 上述的相關(guān)內(nèi)容就是使用 UCP 緩存 JDBC 連接對開發(fā)Oracle數(shù)據(jù)庫密集型應(yīng)用程序的描述,希望會給你帶來一些幫助在此方面。

 

【編輯推薦】

  1. Oracle數(shù)據(jù)庫的異構(gòu)服務(wù)原理描述
  2. Oracle細(xì)粒度如何進(jìn)行訪問
  3. 用Oracle屏蔽英文來提示信息的正確方法
  4. Oracle進(jìn)程中出現(xiàn)帶鎖狀況的解決
  5. Oracle動態(tài)Web開發(fā)實例演示
責(zé)任編輯:佚名 來源: 博客園
相關(guān)推薦

2018-03-22 09:16:06

密集型場景SSD

2022-06-27 14:01:31

LZ4 分析數(shù)據(jù)密集型壓縮算法

2011-11-14 13:29:22

移動應(yīng)用開發(fā)移動開發(fā)移動互聯(lián)網(wǎng)

2025-02-24 09:00:00

CPUI/O密集型任務(wù)

2012-10-08 09:45:22

數(shù)據(jù)密集型處理系統(tǒng)

2012-12-14 11:00:02

VDI桌面虛擬化

2010-04-13 12:23:34

Oracle數(shù)據(jù)庫

2010-04-21 11:27:55

Oracle數(shù)據(jù)庫

2010-04-15 09:36:42

2010-04-22 12:26:10

Oracle數(shù)據(jù)

2010-04-19 11:37:20

Oracle數(shù)據(jù)庫

2020-09-07 07:33:01

NodejsCPU密集型

2011-03-30 11:15:35

SQL Server數(shù)應(yīng)用程序

2022-05-10 08:00:00

數(shù)據(jù)庫數(shù)據(jù)庫監(jiān)控監(jiān)控系統(tǒng)

2010-04-19 09:26:04

Oracle數(shù)據(jù)庫

2016-05-09 10:08:05

IBMIBM FlashSy

2021-02-23 23:06:31

數(shù)據(jù)庫Redis技術(shù)

2010-07-14 13:14:01

SQL Server數(shù)

2010-05-13 13:49:09

MySQL數(shù)據(jù)庫
點贊
收藏

51CTO技術(shù)棧公眾號