Apache James 3 DataBase DataSource

1k Views Asked by At

How to configure the DataSource tag in the Spring-Server.xml ? I have been trying to configure it, but actually i didn't find any useful reference about that : i was writing it this how :

 <data-source class="org.apache.james.util.dbcp.JdbcDataSource" name="JamesDS">
 <driver>oracle.jdbc.driver.OracleDriver</driver>
 <dburl>jdbc:oracle:thin:@localhost:1522:test</dburl>
 <user>James</user>
 <password>123456</password>
 </data-source>
1

There are 1 best solutions below

4
On

You should configure dataSource as a bean, each line you wrote inside should be defined as a property. An example:

<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/myschema" />
    <property name="username" value="root" />
    <property name="password" value="password" />
</bean>

As you can see from the example, you can use different drivers - depends on the DB you're connecting to.

Another example:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/myschema" />
    <property name="username" value="root" />
    <property name="password" value="password" />
</bean>

IMPORTANT:
from Spring docs about DriverManagerDataSource:

This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.

If you need a "real" connection pool outside of a J2EE container, consider Apache's Jakarta Commons DBCP or C3P0. Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full connection pool beans, supporting the same basic properties as this class plus specific settings (such as minimal/maximal pool size etc).

I recommend on reading the following good introduction to JDBC