Java Code Examples for org.apache.tomcat.jdbc.pool.PoolConfiguration#setDriverClassName()
The following examples show how to use
org.apache.tomcat.jdbc.pool.PoolConfiguration#setDriverClassName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatDataSourceService.java From qmq with Apache License 2.0 | 6 votes |
@Override public DataSource makeDataSource(String url, String driverClassName, String username, String pwd) { PoolConfiguration p = new PoolProperties(); p.setMinIdle(0); p.setMaxActive(2); p.setMaxIdle(0); p.setInitialSize(0); p.setMaxWait(10000); p.setDriverClassName(driverClassName); p.setUrl(url); p.setUsername(username); p.setPassword(pwd); p.setValidationQuery("select 1"); p.setTestOnBorrow(true); org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource(); datasource.setPoolProperties(p); return datasource; }
Example 2
Source File: TomcatJdbcDataSourceFactory.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Override public org.apache.tomcat.jdbc.pool.DataSource createDataSource( DataSourceInformation dataSourceInformation) { // create a method scoped instance PoolConfiguration configurationToUse = new PoolProperties(); // copy all general properties BeanUtils.copyProperties(this, configurationToUse); configurationToUse.setDriverClassName(this.databasePlatformSupport .getDriverClassNameForDatabase(dataSourceInformation.getDatabaseType())); configurationToUse.setUrl(this.databasePlatformSupport.getDatabaseUrlForDatabase( dataSourceInformation.getDatabaseType(), dataSourceInformation.getHostName(), dataSourceInformation.getPort(), dataSourceInformation.getDatabaseName())); configurationToUse.setUsername(dataSourceInformation.getUserName()); configurationToUse.setPassword(dataSourceInformation.getPassword()); return new org.apache.tomcat.jdbc.pool.DataSource(configurationToUse); }
Example 3
Source File: SimplePOJOExample.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
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) {} } }
Example 4
Source File: SimplePOJOExample.java From tomcatsrc with Apache License 2.0 | 5 votes |
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) {} } }
Example 5
Source File: SimplePOJOExample.java From Tomcat8-Source-Read with MIT License | 4 votes |
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) { // Ignore } } } }
Example 6
Source File: SimplePOJOAsyncExample.java From Tomcat8-Source-Read with MIT License | 4 votes |
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) { // Ignore } } } }
Example 7
Source File: SimplePOJOAsyncExample.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
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) {} } }
Example 8
Source File: SimplePOJOAsyncExample.java From tomcatsrc with Apache License 2.0 | 4 votes |
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) {} } }