简体   繁体   English

jooq getValue(String fieldName)不同表中具有相同名称的列

[英]jooq getValue(String fieldName) Columns with the same name in different tables

SQL: SQL:

SELECT tblA.hostname, tblB.hostname FROM tblA, tblB ...

When trying to get the hostname from each table, it does not work. 尝试从每个表获取主机名时,它不起作用。 For example, 例如,

String clientHostname = (String) result.getValue("tblA.hostname"); 
String serverHostname = (String) result.getValue("tblB.hostname");

Execution exception: [IllegalArgumentException: Field (tblA.hostname) is not contained in Row (hostname, hostname)] 执行异常:[IllegalArgumentException:行(主机名,主机名)中不包含字段(tblA.hostname)]

Then, another attempt to correct the issue with: 然后,尝试通过以下方法更正此问题:

String clientHostname = (String) result.getValue("hostname"); 
String serverHostname = (String) result.getValue("hostname");

This does not return the desired behavior where clientHostname = tblA.hostname and serverHostname = tblB.hostname, it just returns tblA.hostname for both. 在clientHostname = tblA.hostname和serverHostname = tblB.hostname的情况下,这不会返回所需的行为,而只会为两者返回tblA.hostname。

How do I get the values for both columns? 如何获得两列的值?

Have you tried this? 你有尝试过吗?

"SELECT tblA.hostname AS tblAhostname , tblB.hostname AS tblBhostname FROM tblA, tblB ..." “从tblA,tblB中选择tblA.hostname AS tblAhostname AS ,tblB.hostname AS tblBhostname ...”

String clientHostname = (String) result.getValue("tblAhostname"); String serverHostname = (String) result.getValue("tblBhostname");

Apart from explicitly renaming columns as Erik suggested , you can access qualified column names like this: 除了按照Erik的建议显式重命名列之外,您还可以访问合格的列名,如下所示:

String clientHostname = result.getValue(field(name("tblA", "hostname"), String.class)); 
String serverHostname = result.getValue(field(name("tblB", "hostname"), String.class));

This solution makes use of: 该解决方案利用:

More information about this API can be found in the manual: 可以在手册中找到有关此API的更多信息:

Note, there's also a pending feature request #4578 to allow for using the API the way you have intended. 请注意,还有一个待处理的功能请求#4578允许您按预期的方式使用API​​。

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

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