Reputation: 613
Is anyone actually using Firebird 2.1 with Spring JDBC?
For test purposes I have three simple one table databases set up in MySQL, Postgres and Firebird.
I have no problems connecting and getting data from the MySQL or Postgres.
But I just cannot get Firebird to work.
All I need to change are the jdbc.properties and the pom.xml dependecies for the correct .jar files. It's that easy.
I know that my connection parameters are correct for the Firebird database as I have checked them in a minimal Java command program. I have connected and read data this way.
I get this StackTrace for Firebird:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'org.firebirdsql.jdbc.FBDriver', cause: javax/resource/ResourceException, cause: javax/resource/ResourceException org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)
Very strange, some sort of conflict I guess...
I would like to use Firebird as it is such a simple database but unless I solve this, it's going to be Postgres.
Any help or pointers in the right direction would be very much appreciated.
Upvotes: 3
Views: 5817
Reputation: 772
I think it's already not actual for anyone, but I had to connect with firebird using Spring. It's very similar to Daniel Fath's answer, but in case someone else needs it..
Context:
<bean id="FirebirdDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="org.firebirdsql.pool.FBWrappingDataSource"
p:url="jdbc:firebirdsql://1.1.1.1/your_database_name.fdb"
p:username="user"
p:password="secret" />
Add to your build framework (I use Gradle):
compile group: 'org.firebirdsql.jdbc', name: 'jaybird', version: '2.2.5'
Upvotes: 0
Reputation: 613
OK, here's how to do it:
Add the following to your pom.xml (you need both):
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector-api</artifactId>
<version>1.5</version>
</dependency>
Set your datasource in your ApplicationContext file to:
<bean id="dataSource"
class="org.firebirdsql.pool.FBWrappingDataSource"
p:database="${jdbc.database}"
p:userName="${jdbc.username}"
p:password="${jdbc.password}"
p:type="${jdbc.connection.type}"
p:maxPoolSize="5"
p:minPoolSize="1"
p:pooling="true" />
Note that it uses a Firebird specific pool NOT org.apache.commons.dbcp.BasicDataSource as other databases do.
Note the non-standard parameter names.
Here's my jdbc.properties file:
jdbc.driverClassName=org.firebirdsql.jdbc.FBDriver
jdbc.dialect=org.hibernate.dialect.FirebirdDialect
jdbc.database=/path/to/database.fdb
jdbc.username=admin
jdbc.password=*****
jdbc.defaultAutoCommit=false
jdbc.connection.type=TYPE4
I don't know how to set AutoCommit off yet. Sorry, I'm trying to find out.
Why don't Firebird get this to be STANDARD like other databases? More people might use this great little database then...
Upvotes: 5
Reputation: 613
Just in case any one is interested, here's a follow-up:
I eventually gave up with the above setup, you can only fight so hard and for so long...
The problem was the org.firebirdsql.pool.FBWrappingDataSource.
In the end I got Proxool connection pool working and used that.
<bean id="dataSource"
class="org.logicalcobwebs.proxool.ProxoolDataSource"
p:alias="${jdbc.alias}"
p:driver="${jdbc.driverClassName}"
p:driverUrl="${jdbc.databaseurl}"
p:user="${jdbc.username}"
p:password="${jdbc.password}" />
You'll also have to do something like this:
<dependency>
<groupId>proxool</groupId>
<artifactId>proxool</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>proxool</groupId>
<artifactId>cglib</artifactId>
<version>1.0.0</version>
</dependency>
If you want any help with using Firebird 2 with Spring, please just ask...
Upvotes: 2
Reputation: 242706
Stacktrace looks like javax.resource.ResourceException
class is missed. Perhaps that driver requires classes of J2EE Connector Architecture in the classpath.
Upvotes: 0