Archive for Database

Spring + DBCP

Adding a connection pool to a Spring app is simply a matter of specifying the relevant entries in the Spring servlet configuration file. The XML snippet below shows an example of how a database connection pool can easily be configured.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName">
    <value>net.sourceforge.jtds.jdbc.Driver</value>
  </property>
  <property name="url">
    <value>jdbc:jtds:sqlserver://localhost:1433/db;prepareSQL=0;SendStringParametersAsUnicode=False;</value>
  </property>
  <property name="username">
    <value>username</value>
  </property>
  <property name="password">
    <value>password</value>
  </property>
  <property name="initialSize">
    <value>2</value>
  </property>
  <property name="maxActive">
    <value>5</value>
  </property>
  <property name="maxIdle">
    <value>2</value>
  </property>
</bean>

There are more options that can be used to configure the DBCP connection pool,
eg whether to test connections when getting from the pool or the time to wait
before getting a connection. The complete list of options is given
here.

Advertisements

Comments (16)

mySQL Backup in DOS cmd

  • goto msql install path/..server../bin
  • backup: mysqldump –user=myusername –password=mypassword –opt –databases db01 > c:/data/db01.sql
  • restore: mysql –user=myusername –mypassword db01 < c:/data/db01.sql

Leave a Comment