使用列名从ResultSet中获取小写列 [英] get a lowercase column from ResultSet using column name

查看:426
本文介绍了使用列名从ResultSet中获取小写列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Oracle 12cr1 database. Looks like I can not get a value from ResultSet using the column name if the column name is lowercase.

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

Create table create table "Tab" (col number, "col" varchar2(10)), so the second column is lowercase. If I call getString("col") I will get the value of the first column. If I call getString("\"col\"") I will get Invalid column name error.

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

However, it works fine if I use column index.

推荐答案

来自

From the JDBC API documentation of ResultSet (emphasis mine):

用作获取方法的输入的列名不区分大小写.当使用列名调用getter方法并且多个列具有相同的名称时,将返回第一个匹配列的值.列名选项设计用于在生成结果集的SQL查询中使用列名时使用.对于在查询中未明确命名的列,最好使用列号.如果使用了列名,程序员应注意确保它们唯一地引用了预期的列,这可以通过使用SQL AS子句来确保.

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列标签来使列标签具有唯一性,或者您应该按索引获取该列.

In other words, for the API column names (or, more correctly, column labels) are case insensitive, so what you want is not possible. You will need to make your column labels unique by providing an AS column label, or you should get the column by index instead.

这篇关于使用列名从ResultSet中获取小写列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆