本文整理汇总了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);
}
}
示例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();
}
示例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();
}
示例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));
}
}
示例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;
}
示例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) {}
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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) {}
}
}
示例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));
}
}
}
示例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) {}
}
}
示例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);
}