11 Haziran 2018 Pazartesi

Apache DBCP

Giriş
Tomcat JDBC Connection Pool kütüphanesi Apache DBCP'den daha iyi olduğunu iddia ediyor.

constructor
Şöyle yaparız
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
  <property name="url" value="jdbc:mysql://localhost:3306/chorechart" />  
  <property name="username" value="username" />  
  <property name="password" value="password*" />  
</bean>
Şöyle yaparız.
<bean id="misDataSource" class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
    <property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver"/>
    <property name="url" value="xxx"/>
    <property name="username" value="xxx"/>
    <property name="password" value="xxx"/>
    <property name="maxActive" value="100"/>
    <property name="maxIdle" value="10"/>
    <property name="minIdle" value="1"/>
    <property name="maxWait" value="3000"/>
    <property name="testOnBorrow" value="true"/>
    <property name="testOnReturn" value="false"/>
    <property name="testWhileIdle" value="true"/>
    <property name="timeBetweenEvictionRunsMillis" value="10000"/>
    <property name="numTestsPerEvictionRun" value="50"/>
    <property name="minEvictableIdleTimeMillis" value="10000"/>
    <property name="poolPreparedStatements" value="true"/>
</bean>
getConnection metodu
Şöyle yaparız.
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver")
ds.setUsername("scott");
ds.setPassword("tiger");
ds.setUrl(connectURI);
...
Connection conn = ds.getConnection();

Hiç yorum yok:

Yorum Gönder