简体   繁体   English

如何在ResultSet JayBird中获取String(Table.Column)

[英]How to getString(Table.Column) in ResultSet JayBird

I need to use the database Firebird and for this I use the Jaybird 2.2.9. 我需要使用数据库Firebird,为此,我使用Jaybird 2.2.9。

When I used the MySQL driver, to converter of ResultSet to Object this way: 当我使用MySQL驱动程序时,将ResultSet转换为Object方式是:

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

But with Jaybird the resultSet don't return rs.getString("Table.Column") 但是对于Jaybird, resultSet不会返回rs.getString("Table.Column")

I need this way when I have inner join in SQL . 当我在SQL进行内部SQL时,我需要这种方式。

Anyone help me? 有人帮我吗?

This is my full code 这是我的完整代码

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

The name in jdbc will not have the table in it. jdbc中的名称将没有表格。

You can either 你可以

  • work with positional parameters ( getString (1); and so on ) 使用位置参数( getString (1);等等)

Or 要么

  • define column name alias in your select ( select a.name namefroma from tableone a ) 在您的选择中定义列名称别名( select a.name namefroma from tableone a

Or 要么

  • simply do rs.getString ("column"); 只需做rs.getString(“ column”); without the table prefix if name is unambigous 如果名称明确,则不带表前缀

You can't. 你不能 Jaybird retrieves the columns by its label as specified in JDBC 4.2, section 15.2.3. Jaybird按照JDBC 4.2第15.2.3节中指定的标签检索列。 In Firebird the column label is either the original column name, or the AS alias, the table name isn't part of this. 在Firebird中,列标签要么是原始列名,要么是AS别名,表名不属于该列名。 The extension of MySQL that you can prefix the table name for disambiguation is non-standard. 可以为表名添加歧义的MySQL扩展名是非标准的。

Your options are to specify aliases in the query and retrieve by this aliasname, or to process the result set metadata to find the right indexes for each column and retrieve by index instead. 您的选择是在查询中指定别名并通过此别名进行检索,或处理结果集元数据以找到每个列的正确索引并通过索引进行检索。

However note that in certain queries (for example UNION ), the ResultSetMetaData.getTableName cannot return the table name, as Firebird doesn't "know" it (as you could be applying a UNION to selects from different tables). 但是请注意,在某些查询(例如UNION )中, ResultSetMetaData.getTableName无法返回表名,因为Firebird不会“知道”该表名(因为您可能将UNION应用于从不同表中进行选择)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM