gpt4 book ai didi

java - 使用列名从 ResultSet 获取小写列

转载 作者:行者123 更新时间:2023-11-30 06:52:57 24 4
gpt4 key购买 nike

我使用的是 Oracle 12cr1 数据库。如果列名是小写的,我似乎无法使用列名从 ResultSet 获取值。

创建表创建表“Tab”(col number,“col”varchar2(10)),因此第二列小写。如果我调用 getString("col") ,我将获得第一列的值。如果我调用 getString("\"col\"") 我会收到无效的列名错误。

但是,如果我使用列索引,它就可以正常工作。

最佳答案

来自 ResultSet 的 JDBC API 文档(强调我的):

Column names used as input to getter methods are case insensitive. When a getter method is called with a column name and several columns have the same name, the value of the first matching column will be returned. The column name option is designed to be used when column names are used in the SQL query that generated the result set. For columns that are NOT explicitly named in the query, it is best to use column numbers. If column names are used, the programmer should take care to guarantee that they uniquely refer to the intended columns, which can be assured with the SQL AS clause.

换句话说,对于 API 列名称(或更准确地说,列标签)不区分大小写,因此您想要的东西是不可能的。您需要通过提供 AS 列标签来使列标签唯一,或者您应该通过索引获取列。

关于java - 使用列名从 ResultSet 获取小写列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42406225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com