Java 如何使用Firebird';s jaybird JDBC驱动程序?

Java 如何使用Firebird';s jaybird JDBC驱动程序?,java,jdbc,firebird,jaybird,Java,Jdbc,Firebird,Jaybird,当使用Firebird的jaybird JDBC驱动程序将null绑定到PreparedStatement时,我遇到了一些棘手的情况。下面是一个示例语句: Class.forName("org.firebirdsql.jdbc.FBDriver"); // Observe the "local" in the connection string! Connection con = DriverManager.getConnection( "jdbc:firebirdsql:local:

当使用Firebird的jaybird JDBC驱动程序将
null
绑定到
PreparedStatement
时,我遇到了一些棘手的情况。下面是一个示例语句:

Class.forName("org.firebirdsql.jdbc.FBDriver");

// Observe the "local" in the connection string!
Connection con = DriverManager.getConnection(
    "jdbc:firebirdsql:local:C:/data/firebird/test.db", "TEST", "TEST");

// With this connection, I'm not able to reproduce the issue:
Connection con1 = DriverManager.getConnection(
    "jdbc:firebirdsql:localhost:C:/data/firebird/test.db", "TEST", "TEST");

PreparedStatement stmt = con.prepareStatement(
  "SELECT cast(? as varchar(1)) FROM rdb$database");
stmt.setObject(1, null);
ResultSet rs = stmt.executeQuery();
rs.next();
System.out.println(rs.getString(1));
System.out.println(rs.wasNull());
上述程序的输出为

>
> false
第一行是空字符串。真的应该这样

> null
> true
更改此行

stmt.setObject(1, null);
。。。进入任何一行

stmt.setString(1, null);
stmt.setNull(1, Types.VARCHAR);
。。。这也没用。一种解决方法是在SQL语句中内联
null
文本,而不是将它们绑定到准备好的语句。我错过了什么

详细信息:

  • 数据库:Firebird WI-V2.5.1.26351
  • JDBC驱动程序:jaybird-2.2.0
  • Java版本:JDK1.6.0_24
  • 操作系统:Windows7x64
  • JDBC连接字符串:见上文

我无法在Windows 7 x64上的Jaybird 2.2.0和Firebird 2.1.3(32位)上重现该问题。 复制粘贴源代码并运行它可以精确地生成预期的输出

附加屏幕截图,以防万一:

更新


在Windows XP上的Jaybird 2.2.0和Firebird 2.5.1(32位)上测试,仍然无法再现该问题->与预期完全相同的输出。

我无法在Windows 7 x64上的Jaybird 2.2.0和Firebird 2.1.3(32位)上再现该问题。 复制粘贴源代码并运行它可以精确地生成预期的输出

附加屏幕截图,以防万一:

更新


在Windows XP上的Jaybird 2.2.0和Firebird 2.5.1(32位)上测试,仍然无法再现问题->与预期完全相同的输出。

显然,这是JDBC驱动程序中的一个错误:

它仅在使用此类连接URL时出现:

// Observe the "local" in the connection string!
Connection con = DriverManager.getConnection(
    "jdbc:firebirdsql:local:C:/data/firebird/test.db", "TEST", "TEST");
不适用于这种类型:

// With this connection, I'm not able to reproduce the issue:
Connection con1 = DriverManager.getConnection(
    "jdbc:firebirdsql:localhost:C:/data/firebird/test.db", "TEST", "TEST");

显然,这是JDBC驱动程序中的一个错误:

它仅在使用此类连接URL时出现:

// Observe the "local" in the connection string!
Connection con = DriverManager.getConnection(
    "jdbc:firebirdsql:local:C:/data/firebird/test.db", "TEST", "TEST");
不适用于这种类型:

// With this connection, I'm not able to reproduce the issue:
Connection con1 = DriverManager.getConnection(
    "jdbc:firebirdsql:localhost:C:/data/firebird/test.db", "TEST", "TEST");


在Windows XP上的jaybird 2.2.0和firebird 2.5.1(32位)上测试,仍然无法再现问题->与预期完全相同的输出。感谢您的帮助。显然,这是JDBC驱动程序中的一个错误:在Windows XP上的jaybird 2.2.0和firebird 2.5.1(32位)上进行了测试,仍然无法再现问题->与预期完全相同的输出。感谢您的帮助。显然,这是JDBC驱动程序中的一个bug:下面的答案(以及我自己的复制尝试)表明Jaybird可以按预期工作,最好包含其他信息:完整的Firebird版本、Java版本、操作系统平台和使用的JDBC连接字符串(或者如果您使用的是数据源:其完整的属性集)。如果你有一个工作的复制程序和数据库,你也可以在提交一张票,我会采取一个look@MarkRotteveel:谢谢你的提示。如何获得“完整火鸟版本”?我不知道如何使用,而
rdb$get_context('SYSTEM','ENGINE_VERSION')
返回2.5.1。其余信息已添加到问题
DatabaseMetaData中。getDatabaseProductVersion()
应返回完整的versionOK,但我可以将其缩小到使用连接字符串的范围。我会相应地更新这个问题,在本机部分看起来像个bug。您需要Type2(本机)驱动程序有什么具体原因吗?下面的答案(以及我自己复制的尝试)表明,Jaybird可以按预期工作,最好包含其他信息:完整的Firebird版本、Java版本、操作系统平台和使用的JDBC连接字符串(或者,如果您使用的是数据源:它的全套属性)。如果您有一个工作的复制程序和数据库,您也可以在上提交一张票据,我将接受look@MarkRotteveel:谢谢您的提示。我如何获得“完整Firebird版本”?我不知道如何使用,而
rdb$get\u上下文(“系统”、“引擎版本”)
返回2.5.1。其余信息已添加到问题
DatabaseMetaData.getDatabaseProductVersion()中
应该返回完整版本的OK,但我可以将其缩小到我对连接字符串的使用范围。我会相应地更新问题,看起来像是本机部分中的错误。您需要类型2(本机)的具体原因是什么驱动程序?jdbc:firebirdsql:native://localhost/D:/data/DB/testdatabase.fdbIt 看起来只有当参数是
select
列列表的一部分时才有问题,当它是
where
-条件或
insert
-语句的一部分时,它正确地作为
null
工作etc@MarkRotteveel:我的整数自动化测试表明了另一个问题。这个问题似乎确实与
CAST(?as xxx)有关
操作。如果在
INSERT
UPDATE
语句中使用
CAST
,则任何数据类型都会出现类似的问题。我还对Jaybird 2.2.1和2.3中的错误进行了评论。jdbc:firebirdsql:native://localhost/D:/data/DB/testdatabase.fdbIt 看起来这只是一个问题,当参数是
select
列列表的一部分,当它是
where
-条件或
insert
-语句的一部分时,它正确地作为
null
工作etc@MarkRotteveel:我的集成测试表明了其他一些问题。问题似乎确实与
转换(?as xxx)有关
操作。如果在
INSERT
UPDATE
语句中使用
CAST
,任何数据类型都会出现类似的问题。我还对Jaybird 2.2.1和2.3中的错误进行了评论