中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

哪個網(wǎng)站可以做驗證碼兼職軟件開發(fā)平臺

哪個網(wǎng)站可以做驗證碼兼職,軟件開發(fā)平臺,廠家網(wǎng)站怎么做,淘寶上買網(wǎng)站建設(shè)靠譜嗎DBCP組件 許多Apache項目支持與關(guān)系型數(shù)據(jù)庫進(jìn)行交互。為每個用戶創(chuàng)建一個新連接可能很耗時(通常需要多秒鐘的時鐘時間),以執(zhí)行可能需要毫秒級時間的數(shù)據(jù)庫事務(wù)。對于一個公開托管在互聯(lián)網(wǎng)上的應(yīng)用程序,在同時在線用戶數(shù)量可能非…

DBCP組件

許多Apache項目支持與關(guān)系型數(shù)據(jù)庫進(jìn)行交互。為每個用戶創(chuàng)建一個新連接可能很耗時(通常需要多秒鐘的時鐘時間),以執(zhí)行可能需要毫秒級時間的數(shù)據(jù)庫事務(wù)。對于一個公開托管在互聯(lián)網(wǎng)上的應(yīng)用程序,在同時在線用戶數(shù)量可能非常大的情況下,為每個用戶打開一個連接可能是不可行的。因此,開發(fā)人員通常希望在所有當(dāng)前應(yīng)用程序用戶之間共享一組“池化”的打開連接。在任何給定時間實際執(zhí)行請求的用戶數(shù)量通常只是活躍用戶總數(shù)的非常小的百分比,在請求處理期間是唯一需要數(shù)據(jù)庫連接的時間。應(yīng)用程序本身登錄到DBMS,并在內(nèi)部處理任何用戶賬戶問題。

已經(jīng)有幾個數(shù)據(jù)庫連接池可用,包括Apache產(chǎn)品內(nèi)部和其他地方。這個Commons包提供了一個機(jī)會,來協(xié)調(diào)創(chuàng)建和維護(hù)一個高效、功能豐富的包,以Apache許可證發(fā)布。

commons-dbcp2依賴于commons-pool2中的代碼,以提供底層的對象池機(jī)制。

不同版本

DBCP現(xiàn)在有四個不同的版本,支持不同版本的JDBC。

它的工作原理如下:

開發(fā)中

DBCP 2.5.0及以上版本在Java 8(JDBC 4.2)及以上版本下編譯和運行。

DBCP 2.4.0在Java 7(JDBC 4.1)及以上版本下編譯和運行。

運行中

應(yīng)用程序運行在Java 8及以上版本的情況下,應(yīng)使用DBCP 2.5.0及以上版本的二進(jìn)制文件。 應(yīng)用程序在Java 7下運行時應(yīng)使用DBCP 2.4.0的二進(jìn)制文件。 DBCP 2基于Apache Commons Pool,并提供了與DBCP 1.x相比性能增強(qiáng)、JMX支持以及許多其他新功能。升級到2.x的用戶應(yīng)該注意到Java包名稱已更改,以及Maven坐標(biāo)已更改,因為DBCP 2.x與DBCP 1.x不是二進(jìn)制兼容的。用戶還應(yīng)該注意,一些配置選項(例如maxActive到maxTotal)已更名以與Commons Pool使用的新名稱對齊。

入門例子

您可以從我們的下載頁面下載源代碼和二進(jìn)制文件。

或者,您可以從中央 Maven 存儲庫中提取它:

maven 引入

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-dbcp2</artifactId><version>2.9.0</version>
</dependency>

代碼

https://github.com/apache/commons-dbcp/tree/HEAD/doc

BasicDataSourceExample

這個是最基本的例子,不涉及任何池化能力。

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import javax.sql.DataSource;//
// Here are the dbcp-specific classes.
// Note that they are only used in the setupDataSource
// method. In normal use, your classes interact
// only with the standard JDBC API
//
import org.apache.commons.dbcp2.BasicDataSource;//
// Here's a simple example of how to use the BasicDataSource.
////
// Note that this example is very similar to the PoolingDriver
// example.//
// To compile this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
// in your classpath.
//
// To run this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
//  * commons-logging-1.2.jar
// in your classpath.
//
//
// Invoke the class using two arguments:
//  * the connect string for your underlying JDBC driver
//  * the query you'd like to execute
// You'll also want to ensure your underlying JDBC driver
// is registered.  You can use the "jdbc.drivers"
// property to do this.
//
// For example:
//  java -Djdbc.drivers=org.h2.Driver \
//       -classpath commons-pool2-2.3.jar:commons-dbcp2-2.1.jar:commons-logging-1.2.jar:h2-1.3.152.jar:. \
//       BasicDataSourceExample \
//       "jdbc:h2:~/test" \
//       "SELECT 1"
//
public class BasicDataSourceExample {public static void main(String[] args) {// First we set up the BasicDataSource.// Normally this would be handled auto-magically by// an external configuration, but in this example we'll// do it manually.//System.out.println("Setting up data source.");DataSource dataSource = setupDataSource(args[0]);System.out.println("Done.");//// Now, we can use JDBC DataSource as we normally would.//Connection conn = null;Statement stmt = null;ResultSet rset = null;try {System.out.println("Creating connection.");conn = dataSource.getConnection();System.out.println("Creating statement.");stmt = conn.createStatement();System.out.println("Executing statement.");rset = stmt.executeQuery(args[1]);System.out.println("Results:");int numcols = rset.getMetaData().getColumnCount();while(rset.next()) {for(int i=1;i<=numcols;i++) {System.out.print("\t" + rset.getString(i));}System.out.println("");}} catch (SQLException e) {e.printStackTrace();} finally {try {if (rset != null)rset.close();} catch (Exception e) {}try {if (stmt != null)stmt.close();} catch (Exception e) {}try {if (conn != null)conn.close();} catch (Exception e) {}}}public static DataSource setupDataSource(String connectURI) {BasicDataSource ds = new BasicDataSource();ds.setDriverClassName("org.h2.Driver");ds.setUrl(connectURI);return ds;}public static void printDataSourceStats(DataSource ds) {BasicDataSource bds = (BasicDataSource) ds;System.out.println("NumActive: " + bds.getNumActive());System.out.println("NumIdle: " + bds.getNumIdle());}public static void shutdownDataSource(DataSource ds) throws SQLException {BasicDataSource bds = (BasicDataSource) ds;bds.close();}
}

PoolingDataSourceExample

這里的 datasource 是池化的。

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;//
// Here are the dbcp-specific classes.
// Note that they are only used in the setupDataSource
// method. In normal use, your classes interact
// only with the standard JDBC API
//
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolingDataSource;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;//
// Here's a simple example of how to use the PoolingDataSource.
////
// Note that this example is very similar to the PoolingDriver
// example.  In fact, you could use the same pool in both a
// PoolingDriver and a PoolingDataSource
////
// To compile this example, you'll want:
//  * commons-pool2-2.3.jar
//  * commons-dbcp2-2.1.jar
// in your classpath.
//
// To run this example, you'll want:
//  * commons-pool2-2.3.jar
//  * commons-dbcp2-2.1.jar
//  * commons-logging-1.2.jar
//  * the classes for your (underlying) JDBC driver
// in your classpath.
//
// Invoke the class using two arguments:
//  * the connect string for your underlying JDBC driver
//  * the query you'd like to execute
// You'll also want to ensure your underlying JDBC driver
// is registered.  You can use the "jdbc.drivers"
// property to do this.
//
// For example:
//  java -Djdbc.drivers=org.h2.Driver \
//       -classpath commons-pool2-2.3.jar:commons-dbcp2-2.1.jar:commons-logging-1.2.jar:h2-1.3.152.jar:. \
//       PoolingDataSourceExample \
//       "jdbc:h2:~/test" \
//       "SELECT 1"
//
public class PoolingDataSourceExample {public static void main(String[] args) {//// First we load the underlying JDBC driver.// You need this if you don't use the jdbc.drivers// system property.//System.out.println("Loading underlying JDBC driver.");try {Class.forName("org.h2.Driver");} catch (ClassNotFoundException e) {e.printStackTrace();}System.out.println("Done.");//// Then, we set up the PoolingDataSource.// Normally this would be handled auto-magically by// an external configuration, but in this example we'll// do it manually.//System.out.println("Setting up data source.");DataSource dataSource = setupDataSource(args[0]);System.out.println("Done.");//// Now, we can use JDBC DataSource as we normally would.//Connection conn = null;Statement stmt = null;ResultSet rset = null;try {System.out.println("Creating connection.");conn = dataSource.getConnection();System.out.println("Creating statement.");stmt = conn.createStatement();System.out.println("Executing statement.");rset = stmt.executeQuery(args[1]);System.out.println("Results:");int numcols = rset.getMetaData().getColumnCount();while(rset.next()) {for(int i=1;i<=numcols;i++) {System.out.print("\t" + rset.getString(i));}System.out.println("");}} catch (SQLException e) {e.printStackTrace();} finally {try {if (rset != null)rset.close();} catch (Exception e) {}try {if (stmt != null)stmt.close();} catch (Exception e) {}try {if (conn != null)conn.close();} catch (Exception e) {}}}// 這里的 datasource 是池化的。public static DataSource setupDataSource(String connectURI) {//// First, we'll create a ConnectionFactory that the// pool will use to create Connections.// We'll use the DriverManagerConnectionFactory,// using the connect string passed in the command line// arguments.//ConnectionFactory connectionFactory =new DriverManagerConnectionFactory(connectURI, null);//// Next we'll create the PoolableConnectionFactory, which wraps// the "real" Connections created by the ConnectionFactory with// the classes that implement the pooling functionality.//PoolableConnectionFactory poolableConnectionFactory =new PoolableConnectionFactory(connectionFactory, null);//// Now we'll need a ObjectPool that serves as the// actual pool of connections.//// We'll use a GenericObjectPool instance, although// any ObjectPool implementation will suffice.//ObjectPool<PoolableConnection> connectionPool =new GenericObjectPool<>(poolableConnectionFactory);// Set the factory's pool property to the owning poolpoolableConnectionFactory.setPool(connectionPool);//// Finally, we create the PoolingDriver itself,// passing in the object pool we created.//PoolingDataSource<PoolableConnection> dataSource =new PoolingDataSource<>(connectionPool);return dataSource;}
}

PoolingDriverExample.java

這里用的是 dbcp 的驅(qū)動實現(xiàn)池化的?

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.dbcp2.PoolingDriver;
//
// Here are the dbcp-specific classes.
// Note that they are only used in the setupDriver
// method. In normal use, your classes interact
// only with the standard JDBC API
//
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;//
// Here's a simple example of how to use the PoolingDriver.
//// To compile this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
// in your classpath.
//
// To run this example, you'll want:
//  * commons-pool-2.3.jar
//  * commons-dbcp-2.1.jar 
//  * commons-logging-1.2.jar
// in your classpath.
//
// Invoke the class using two arguments:
//  * the connect string for your underlying JDBC driver
//  * the query you'd like to execute
// You'll also want to ensure your underlying JDBC driver
// is registered.  You can use the "jdbc.drivers"
// property to do this.
//
// For example:
//  java -Djdbc.drivers=org.h2.Driver \
//       -classpath commons-pool2-2.3.jar:commons-dbcp2-2.1.jar:commons-logging-1.2.jar:h2-1.3.152.jar:. \
//       PoolingDriverExample \
//       "jdbc:h2:~/test" \
//       "SELECT 1"
//
public class PoolingDriverExample {public static void main(String[] args) {//// First we load the underlying JDBC driver.// You need this if you don't use the jdbc.drivers// system property.//System.out.println("Loading underlying JDBC driver.");try {Class.forName("org.h2.Driver");} catch (ClassNotFoundException e) {e.printStackTrace();}System.out.println("Done.");//// Then we set up and register the PoolingDriver.// Normally this would be handled auto-magically by// an external configuration, but in this example we'll// do it manually.//System.out.println("Setting up driver.");try {setupDriver(args[0]);} catch (Exception e) {e.printStackTrace();}System.out.println("Done.");//// Now, we can use JDBC as we normally would.// Using the connect string//  jdbc:apache:commons:dbcp:example// The general form being://  jdbc:apache:commons:dbcp:<name-of-pool>//Connection conn = null;Statement stmt = null;ResultSet rset = null;try {System.out.println("Creating connection.");conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:example");System.out.println("Creating statement.");stmt = conn.createStatement();System.out.println("Executing statement.");rset = stmt.executeQuery(args[1]);System.out.println("Results:");int numcols = rset.getMetaData().getColumnCount();while(rset.next()) {for(int i=1;i<=numcols;i++) {System.out.print("\t" + rset.getString(i));}System.out.println("");}} catch (SQLException e) {e.printStackTrace();} finally {try {if (rset != null)rset.close();} catch (Exception e) {}try {if (stmt != null)stmt.close();} catch (Exception e) {}try {if (conn != null)conn.close();} catch (Exception e) {}}// Display some pool statisticstry {printDriverStats();} catch (Exception e) {e.printStackTrace();}// closes the pooltry {shutdownDriver();} catch (Exception e) {e.printStackTrace();}}public static void setupDriver(String connectURI) throws Exception {//// First, we'll create a ConnectionFactory that the// pool will use to create Connections.// We'll use the DriverManagerConnectionFactory,// using the connect string passed in the command line// arguments.//ConnectionFactory connectionFactory =new DriverManagerConnectionFactory(connectURI, null);//// Next, we'll create the PoolableConnectionFactory, which wraps// the "real" Connections created by the ConnectionFactory with// the classes that implement the pooling functionality.//PoolableConnectionFactory poolableConnectionFactory =new PoolableConnectionFactory(connectionFactory, null);//// Now we'll need a ObjectPool that serves as the// actual pool of connections.//// We'll use a GenericObjectPool instance, although// any ObjectPool implementation will suffice.//ObjectPool<PoolableConnection> connectionPool =new GenericObjectPool<>(poolableConnectionFactory);// Set the factory's pool property to the owning poolpoolableConnectionFactory.setPool(connectionPool);//// Finally, we create the PoolingDriver itself...//Class.forName("org.apache.commons.dbcp2.PoolingDriver");PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");//// ...and register our pool with it.//driver.registerPool("example", connectionPool);//// Now we can just use the connect string "jdbc:apache:commons:dbcp:example"// to access our pool of Connections.//}public static void printDriverStats() throws Exception {PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");ObjectPool<? extends Connection> connectionPool = driver.getConnectionPool("example");System.out.println("NumActive: " + connectionPool.getNumActive());System.out.println("NumIdle: " + connectionPool.getNumIdle());}public static void shutdownDriver() throws Exception {PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");driver.closePool("example");}
}
http://www.risenshineclean.com/news/50690.html

相關(guān)文章:

  • 百度 醫(yī)療網(wǎng)站建設(shè)公司做網(wǎng)站需要多少錢
  • php企業(yè)網(wǎng)站demo長沙網(wǎng)站建設(shè)
  • 西安給大學(xué)做網(wǎng)站公司國外瀏覽器搜索引擎入口
  • 錦州 做網(wǎng)站茂名網(wǎng)站建設(shè)制作
  • 昆明網(wǎng)站做谷歌官網(wǎng)下載app
  • 濟(jì)南網(wǎng)站建設(shè)就選搜點網(wǎng)絡(luò)ok線上營銷的方式
  • 公司建設(shè)網(wǎng)站的費用廣告文案經(jīng)典范例200字
  • 開平 做一網(wǎng)站南京seo整站優(yōu)化技術(shù)
  • wordpress4.8內(nèi)存seo自動工具
  • 外貿(mào)客戶管理軟件排名排名優(yōu)化方法
  • 做網(wǎng)站通常用的軟件肇慶網(wǎng)站建設(shè)制作
  • css網(wǎng)站做光暈效果產(chǎn)品推廣方案范例
  • 楊園建設(shè)社區(qū)網(wǎng)站電商seo名詞解釋
  • 多站點網(wǎng)站群的建設(shè)與管理社交媒體營銷
  • 網(wǎng)站開發(fā)的前臺開發(fā)工具武漢seo百度
  • 做垂直網(wǎng)站營銷策劃書格式及范文
  • 簡單自適應(yīng)網(wǎng)站友情鏈接交換平臺有哪些
  • 網(wǎng)站建站費用多少廣州百度關(guān)鍵詞搜索
  • 項目建設(shè)管理福州百度seo排名軟件
  • 大型門戶網(wǎng)站都有抖音關(guān)鍵詞排名優(yōu)化軟件
  • 濟(jì)南最好的網(wǎng)站制作公司哪家好第一設(shè)計
  • wordpress安裝后輸入什么域名電腦系統(tǒng)優(yōu)化軟件排行榜
  • 個人博客網(wǎng)站模板素材百度搜索排名機(jī)制
  • 美食欣賞網(wǎng)站瀏覽器谷歌手機(jī)版下載
  • 網(wǎng)站建站智能系統(tǒng)seo網(wǎng)上課程
  • 微信第三方做網(wǎng)站需要費用嗎如何用google搜索產(chǎn)品關(guān)鍵詞
  • 公司網(wǎng)站上榮譽(yù)墻怎么做西seo優(yōu)化排名
  • 可直接進(jìn)入網(wǎng)站的代碼網(wǎng)絡(luò)營銷策略實施的步驟
  • 寧波專業(yè)網(wǎng)站建設(shè)公司什么是淘寶搜索關(guān)鍵詞
  • 做網(wǎng)站什么軟件荊門剛剛發(fā)布的