如何在结果集中获取字符串(Table.Column) JayBird

How to getString(Table.Column) in ResultSet JayBird

我需要使用数据库 Firebird,为此我使用 Jaybird 2.2.9。

当我使用 MySQL 驱动程序时,ResultSetObject 的转换器是这样的:

empresa.setBairro(rs.getString("empresa.bairro")); // (Table.Column)
empresa.setCep(rs.getString("empresa.cep")); // (Table.Column)
empresa.setCidade(rs.getString("empresa.cidade")); // (Table.Column)

但是对于 Jaybird,resultSet 不会 return rs.getString("Table.Column")

当我在 SQL 中进行内部连接时,我需要这种方式。

有人帮帮我吗?

这是我的完整代码

public ContaLivros converterContaLivros(ResultSet rs, Integer linha) throws Exception {
    if (rs.first()) {

        rs.absolute(linha);

        ContaLivros obj = new ContaLivros();

        obj.setId(rs.getLong("cad_conta.auto_id"));
        obj.setNome(rs.getString("cad_conta.nome"));


        if (contain("cad_banco.auto_id", rs)) {

            obj.setBancoLivros(converterBancoLivros(rs, linha));
        } else {

            obj.setBancoLivros(new BancoLivros(rs.getLong("cad_conta.banco"), null, null, null));
        }
        obj.setAgencia(rs.getInt("cad_conta.agencia"));
        obj.setAgenciaDigito(rs.getInt("cad_conta.agencia_digito"));
        obj.setConta(rs.getInt("cad_conta.conta"));
        obj.setContaDigito(rs.getInt("cad_conta.conta_digito"));
        obj.setLimite(rs.getDouble("cad_conta.limite"));
        obj.setAtivo(rs.getString("cad_conta.ativo"));

        return obj;
    } else {
        return null;
    }
}

jdbc 中的名称不会包含 table。

你可以

  • 使用位置参数(getString (1); 等等)

  • 在 select (select a.name namefroma from tableone a )
  • 中定义列名别名

  • 简单地做rs.getString ("column");没有 table 前缀如果名称明确

你不能。 Jaybird 按 JDBC 4.2,第 15.2.3 节中指定的标签检索列。在 Firebird 中,列标签是原始列名或 AS 别名,table 名称不是其中的一部分。您可以在 table 名称前添加前缀以消除歧义的 MySQL 的扩展名是 non-standard.

您的选择是在查询中指定别名并按此别名检索,或者处理结果集元数据以为每列找到正确的索引并按索引检索。

但是请注意,在某些查询中(例如 UNION),ResultSetMetaData.getTableName 不能 return table 名称,因为 Firebird 不会 "know" 它(因为您可以应用 UNION 从不同的 table 中进行选择)。