當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSource.setPoolProperties方法代碼示例

本文整理匯總了Java中org.apache.tomcat.jdbc.pool.DataSource.setPoolProperties方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSource.setPoolProperties方法的具體用法?Java DataSource.setPoolProperties怎麽用?Java DataSource.setPoolProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.tomcat.jdbc.pool.DataSource的用法示例。


在下文中一共展示了DataSource.setPoolProperties方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: connectToDb

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
/**
 * Connects to specified database.
 */
private void connectToDb() {
    this.loadProperties();
    PoolProperties p = new PoolProperties();
    p.setUrl(this.prs.getProperty("url"));
    p.setDriverClassName(SQL_DRIVER);
    p.setUsername(this.prs.getProperty("user"));
    p.setPassword(this.prs.getProperty("password"));
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);
    try {
        this.conn = datasource.getConnection();
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
    }
}
 
開發者ID:dionisius1976,項目名稱:java-a-to-z,代碼行數:19,代碼來源:DbManager.java

示例2: connectToDb

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
/**
 * Connects to specified database.
 */
private void connectToDb() {
    this.loadProperties();

    PoolProperties p = new PoolProperties();
    DataSource datasource = new DataSource();
    p.setUrl(this.prs.getProperty("url"));
    p.setDriverClassName(SQL_DRIVER);
    p.setUsername(this.prs.getProperty("user"));
    p.setPassword(this.prs.getProperty("password"));
    datasource.setPoolProperties(p);
    try {
        this.conn = datasource.getConnection();
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
    }
    this.createTable();
}
 
開發者ID:dionisius1976,項目名稱:java-a-to-z,代碼行數:21,代碼來源:DbManager.java

示例3: connectToDb

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
/**
 * Connects to specified database.
 */
private void connectToDb() {
    this.loadProperties();
    PoolProperties p = new PoolProperties();
    p.setUrl(this.prs.getProperty("url"));
    p.setDriverClassName(SQL_DRIVER);
    p.setUsername(this.prs.getProperty("user"));
    p.setPassword(this.prs.getProperty("password"));
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);
    try {
        this.conn = datasource.getConnection();
        System.out.println(this.conn);
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
    }
    this.createTable();
}
 
開發者ID:dionisius1976,項目名稱:java-a-to-z,代碼行數:21,代碼來源:DbManager.java

示例4: setupDataSource

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
private static void setupDataSource(Isolation isolation) {
  ds = new DataSource();

  try {    
    ds.setPoolProperties(getPoolProperties()); //set earlier to avoid overriding the isolation setting
    
    ds.setMaxActive(100);
    
    if (isolation == Isolation.NONE) {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE);
    } else if (isolation == Isolation.READ_COMMITTED) {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
      ds.setDefaultAutoCommit(false);
    } else {
      ds.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
      ds.setDefaultAutoCommit(false);
    }
    
    dsSet = true;
    Log.getLogWriter().info("tomcat data source url is set as " + ds.getUrl());
    Log.getLogWriter().info("tomcat data source DefaultTransactionIsolation is set to " + ds.getDefaultTransactionIsolation());
    Log.getLogWriter().info("tomcat data source DefaultAutoCommit is set to " + ds.getDefaultAutoCommit());
  } catch (Exception e) {
    throw new TestException("could not set data source" + TestHelper.getStackTrace(e));
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:27,代碼來源:PooledConnectionTomcat.java

示例5: createDatasource

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
protected static javax.sql.DataSource createDatasource(Properties properties) {

    PoolProperties p = new PoolProperties();
    p.setUrl(properties.getProperty("databaseUrl"));
    p.setDriverClassName(properties.getProperty("databaseDriver"));
    p.setUsername(properties.getProperty("databaseUser"));
    p.setPassword(properties.getProperty("databasePassword"));

    p.setJmxEnabled(false);

    p.setMaxActive(100);
    p.setInitialSize(10);

    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    return datasource;
  }
 
開發者ID:camunda,項目名稱:camunda-bpm-platform,代碼行數:19,代碼來源:PerfTestProcessEngine.java

示例6: main

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    PoolConfiguration p = new PoolProperties();
    p.setUrl("jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
    p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUsername("root");
    p.setPassword("password");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    Connection con = null;
    try {
      con = datasource.getConnection();
      Statement st = con.createStatement();
      ResultSet rs = st.executeQuery("select * from user");
      int cnt = 1;
      while (rs.next()) {
          System.out.println((cnt++)+". Host:" +rs.getString("Host")+" User:"+rs.getString("User")+" Password:"+rs.getString("Password"));
      }
      rs.close();
      st.close();
    } finally {
      if (con!=null) try {con.close();}catch (Exception ignore) {}
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:41,代碼來源:SimplePOJOExample.java

示例7: createPool

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
public static void createPool() throws Exception {
// Modify this code in order to extract a Connection from your
// connection pooling system:

// Driver parameters to use:
String driverClassName = "org.postgresql.Driver";
String url = "jdbc:postgresql://localhost:5432/kawansoft_example";
String username = "user1";
String password = "password1";

// Creating the DataSource bean and populating the values:
// Mandatory values to set
PoolProperties p = new PoolProperties();
p.setDriverClassName(driverClassName);
p.setUrl(url);
p.setUsername(username);
p.setPassword(password);

// Other possible values to set
p.setTestOnBorrow(true);
p.setValidationQuery("SELECT 1");
p.setTestOnReturn(false);
p.setValidationInterval(30000);
p.setTimeBetweenEvictionRunsMillis(30000);
p.setMaxActive(2);
p.setInitialSize(2);
p.setMaxWait(10000);
p.setRemoveAbandonedTimeout(60);
p.setMinEvictableIdleTimeMillis(30000);
p.setMinIdle(2);
p.setMaxIdle(2);
p.setLogAbandoned(true);
p.setRemoveAbandoned(true);
p.setJdbcInterceptors("ConnectionState;StatementFinalizer");

dataSource = new DataSource();
dataSource.setPoolProperties(p);

   }
 
開發者ID:kawansoft,項目名稱:aceql-http,代碼行數:40,代碼來源:TestTomcatJdbcPoolBehavior.java

示例8: connectToDb

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
/**
 * Connects to specified database.
 */
private void connectToDb() {
    PoolProperties p = new PoolProperties();
    p.setUrl(this.prs.getProperty("url"));
    p.setDriverClassName(SQL_DRIVER);
    p.setUsername(this.prs.getProperty("user"));
    p.setPassword(this.prs.getProperty("password"));
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);
    try {
        this.conn = datasource.getConnection();
    } catch (SQLException e) {
        LOG.error(e.getMessage(), e);
    }
}
 
開發者ID:dionisius1976,項目名稱:java-a-to-z,代碼行數:18,代碼來源:DbManager.java

示例9: setUp

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
@Before
public void setUp() {
    PoolProperties p = new PoolProperties();
    p.setUrl("jdbc:mysql://localhost:3306/mysql");
    p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUsername("root");
    p.setPassword("");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setFairQueue(true);
    p.setJdbcInterceptors(
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" +
                    "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    dataSource = new DataSource();
    dataSource.setPoolProperties(p);
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:30,代碼來源:DataSourceTest.java

示例10: setUp

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
@Before
public void setUp() {
    PoolProperties p = new PoolProperties();
    p.setUrl("jdbc:mysql://localhost:3306/admin");
    p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUsername("root");
    p.setPassword("");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setFairQueue(true);
    p.setJdbcInterceptors(
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" +
                    "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    dataSource = new DataSource();
    dataSource.setPoolProperties(p);
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:30,代碼來源:DbUtilsTest.java

示例11: setUp

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
@Before
public void setUp() {
    PoolProperties p = new PoolProperties();
    p.setUrl("jdbc:mysql://127.0.0.1:3308/admin");
    p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUsername("root");
    p.setPassword("");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setFairQueue(true);
    p.setJdbcInterceptors(
            "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;" +
                    "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    dataSource = new DataSource();
    dataSource.setPoolProperties(p);
}
 
開發者ID:edgar615,項目名稱:javase-study,代碼行數:30,代碼來源:Sql2oTest.java

示例12: main

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    PoolConfiguration p = new PoolProperties();
    p.setUrl("jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
    p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUsername("root");
    p.setPassword("password");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p); 
    
    Connection con = null;
    try {            
      con = datasource.getConnection();
      Statement st = con.createStatement();
      ResultSet rs = st.executeQuery("select * from user");
      int cnt = 1;
      while (rs.next()) {
          System.out.println((cnt++)+". Host:" +rs.getString("Host")+" User:"+rs.getString("User")+" Password:"+rs.getString("Password"));
      }
      rs.close();
      st.close();
    } finally {
      if (con!=null) try {con.close();}catch (Exception ignore) {}
    }  
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:41,代碼來源:SimplePOJOExample.java

示例13: initial

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
@Test
public void initial() throws Exception {
    PoolProperties p = new PoolProperties();
    p.setUrl("jdbc:h2:mem");
    p.setDriverClassName("org.h2.Driver");
    p.setUsername("sa");
    p.setPassword("sa");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
            + "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    DataSource dataSource = new DataSource();
    dataSource.setPoolProperties(p);
    try (Connection connection = dataSource.getConnection(); 
            Statement statement = connection.createStatement(); 
            ResultSet resultSet = statement.executeQuery("select 1")) {
        while (resultSet.next()) {
            logger.info("{}", resultSet.getObject(1));
        }
    }          
}
 
開發者ID:evanx,項目名稱:chronic,代碼行數:35,代碼來源:TestTomcatPool.java

示例14: main

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    PoolConfiguration p = new PoolProperties();
    p.setFairQueue(true);
    p.setUrl("jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
    p.setDriverClassName("com.mysql.jdbc.Driver");
    p.setUsername("root");
    p.setPassword("password");
    p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setTestOnReturn(false);
    p.setValidationInterval(30000);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(10);
    p.setMaxWait(10000);
    p.setRemoveAbandonedTimeout(60);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(10);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);

    Connection con = null;
    try {
      Future<Connection> future = datasource.getConnectionAsync();
      while (!future.isDone()) {
          System.out.println("Connection is not yet available. Do some background work");
          try {
              Thread.sleep(100); //simulate work
          }catch (InterruptedException x) {
              Thread.interrupted();
          }
      }
      con = future.get(); //should return instantly
      Statement st = con.createStatement();
      ResultSet rs = st.executeQuery("select * from user");
      int cnt = 1;
      while (rs.next()) {
          System.out.println((cnt++)+". Host:" +rs.getString("Host")+" User:"+rs.getString("User")+" Password:"+rs.getString("Password"));
      }
      rs.close();
      st.close();
    } finally {
      if (con!=null) try {con.close();}catch (Exception ignore) {}
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:51,代碼來源:SimplePOJOAsyncExample.java

示例15: addDataSource

import org.apache.tomcat.jdbc.pool.DataSource; //導入方法依賴的package包/類
public static void addDataSource(String key, Properties props) throws SQLException{
    String cs = props.getProperty("jdbcconnectstring");
    Matcher o = oraclePattern.matcher(cs);
    Matcher m = mysqlPattern.matcher(cs);
    int currType;
    
    PoolProperties p = new PoolProperties();
    p.setUrl(props.getProperty("jdbcconnectstring"));
    if (o.matches()) {
    	p.setDriverClassName("oracle.jdbc.OracleDriver");
    	currType=ORACLE;
    } else if (m.matches()) {
    	p.setDriverClassName("com.mysql.jdbc.Driver");
    	currType=MYSQL;
    } else {
        throw new SQLException("Unknown database type in " + cs);
    }
    p.setUsername(props.getProperty("user"));
    p.setPassword(props.getProperty("passwd"));
    //p.setJmxEnabled(true);
    p.setTestWhileIdle(false);
    p.setTestOnBorrow(true);
    p.setValidationQuery("SELECT 1");
    p.setValidationInterval(30000);
    p.setTestOnReturn(false);
    p.setTimeBetweenEvictionRunsMillis(30000);
    p.setMaxActive(100);
    p.setInitialSize(5);
    p.setMaxWait(1000);
    p.setRemoveAbandonedTimeout(30000);
    p.setMinEvictableIdleTimeMillis(30000);
    p.setMinIdle(5);
    p.setLogAbandoned(true);
    p.setRemoveAbandoned(true);
    p.setJdbcInterceptors(
      "org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"+
      "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
    DataSource datasource = new DataSource();
    datasource.setPoolProperties(p);
    sourceType.put(datasource, currType);
    sources.put(key, datasource);
}
 
開發者ID:seqcode,項目名稱:seqcode-core,代碼行數:43,代碼來源:DatabaseConnectionManager.java


注:本文中的org.apache.tomcat.jdbc.pool.DataSource.setPoolProperties方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。