Spring JDBC 和 Firebird 数据库

发布于 2024-10-17 08:10:28 字数 945 浏览 3 评论 0原文

有人实际上使用 Firebird 2.1 和 Spring JDBC 吗?

出于测试目的,我在 MySQL、Postgres 和 Firebird 中设置了三个简单的单表数据库。

我在连接 MySQL 或 Postgres 并获取数据时没有任何问题。

但我就是无法让 Firebird 工作。

我需要更改的是正确的 .jar 文件的 jdbc.properties 和 pom.xml 依赖项。就是这么简单。

我知道 Firebird 数据库的连接参数是正确的,因为我已经在最小的 Java 命令程序中检查了它们。我已经通过这种方式连接并读取数据。

我得到 Firebird 的 StackTrace:

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;嵌套异常是 org.apache.commons.dbcp.SQLNestedException:无法加载 JDBC 驱动程序类“org.firebirdsql.jdbc.FBDriver”,原因:javax/resource/ResourceException,原因:javax/resource/ResourceException org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)

非常奇怪,我猜有某种冲突...

我想使用 Firebird,因为它是一个如此简单的数据库,但除非我解决这个问题,否则它是将是 Postgres。

任何正确方向的帮助或指示将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

围归者 2024-10-24 08:10:28

好的,具体做法如下:

将以下内容添加到您的 pom.xml(两者都需要):

    <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>

将 ApplicationContext 文件中的数据源设置为:

<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" />

请注意,它使用 Firebird 特定池而不是 org.apache.commons.dbcp.BasicDataSource 作为其他数据库也可以。

请注意非标准参数名称。

这是我的 jdbc.properties 文件:

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

我还不知道如何关闭 AutoCommit。抱歉,我正在尝试找出答案。

为什么 Firebird 不像其他数据库那样将其设为标准?那么更多的人可能会使用这个很棒的小数据库......

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...

满栀 2024-10-24 08:10:28

万一有人感兴趣,这里有一个后续:

我最终放弃了上面的设置,你只能奋战这么长时间......

问题是 org.firebirdsql .pool.FBWrappingDataSource。

最后我让 Proxool 连接池工作并使用它。

<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}" />

您还必须执行以下操作:

    <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>

如果您需要有关使用 Firebird 2 和 Spring 的任何帮助,请询问...

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...

醉态萌生 2024-10-24 08:10:28

Stacktrace 看起来像是缺少 javax.resource.ResourceException 类。也许该驱动程序需要类路径中的 J2EE 连接器体系结构 类。

Stacktrace looks like javax.resource.ResourceException class is missed. Perhaps that driver requires classes of J2EE Connector Architecture in the classpath.

懷念過去 2024-10-24 08:10:28

我认为这对任何人来说都不是现实的,但我必须使用 Spring 与 firebird 连接。它与 Daniel Fath 的答案非常相似,但以防万一其他人需要它..

上下文:

<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" />

添加到您的构建框架(我使用 Gradle):

   compile group: 'org.firebirdsql.jdbc', name: 'jaybird', version: '2.2.5'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文