2

在绑定nullPreparedStatementFirebird 的 jaybird JDBC 驱动程序时,我遇到了一些极端情况。这是一个示例语句:

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文字,而不是将它们绑定到准备好的语句。我错过了什么?

细节:

  • 数据库:火鸟 WI-V2.5.1.26351
  • JDBC驱动:jaybird-2.2.0
  • Java版本:JDK 1.6.0_24
  • 操作系统:Windows 7 x64
  • JDBC 连接字符串:见上文。
4

2 回答 2

3

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

附上截图以防万一:

在此处输入图像描述

更新

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

于 2012-08-24T15:47:09.527 回答
1

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

http://tracker.firebirdsql.org/browse/JDBC-271

它仅在使用这种连接 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");
于 2012-08-25T09:05:29.427 回答