Spring JDBC 和 Firebird 数据库
有人实际上使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,具体做法如下:
将以下内容添加到您的 pom.xml(两者都需要):
将 ApplicationContext 文件中的数据源设置为:
请注意,它使用 Firebird 特定池而不是 org.apache.commons.dbcp.BasicDataSource 作为其他数据库也可以。
请注意非标准参数名称。
这是我的 jdbc.properties 文件:
我还不知道如何关闭 AutoCommit。抱歉,我正在尝试找出答案。
为什么 Firebird 不像其他数据库那样将其设为标准?那么更多的人可能会使用这个很棒的小数据库......
OK, here's how to do it:
Add the following to your pom.xml (you need both):
Set your datasource in your ApplicationContext file to:
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:
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...
万一有人感兴趣,这里有一个后续:
我最终放弃了上面的设置,你只能奋战这么长时间......
问题是 org.firebirdsql .pool.FBWrappingDataSource。
最后我让 Proxool 连接池工作并使用它。
您还必须执行以下操作:
如果您需要有关使用 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.
You'll also have to do something like this:
If you want any help with using Firebird 2 with Spring, please just ask...
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.我认为这对任何人来说都不是现实的,但我必须使用 Spring 与 firebird 连接。它与 Daniel Fath 的答案非常相似,但以防万一其他人需要它..
上下文:
添加到您的构建框架(我使用 Gradle):
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:
Add to your build framework (I use Gradle):