com.ibm.db2.jcc.b.SqlException:无效参数:未知列名 COL1

发布于 2024-08-12 02:34:52 字数 483 浏览 4 评论 0原文

当尝试使用 rs.getString(" 访问我的 resultSet 时,我收到此错误 com.ibm.db2.jcc.b.SqlException: 无效参数:未知列 名称 COL1 COL1")。
我的 SQL 查询是:从 table1 中选择 UPPER(COL1)。 相同的查询和 Java 代码在 DB2 v8(类型 2 驱动程序) 上运行良好,但在与 DB2 v9(类型 4 驱动程序)一起使用时抛出上述异常。

但是我可以通过添加别名来解决此错误, 修改后的查询:从 table1 中选择 UPPER(COL1) COL1。

以上查询适用于 DB2 v8 和 v9。 这是否意味着,在 DB2 9 中,我们在使用 (upper,trim,..) 等函数时必须提供别名???

谢谢

i was getting this error com.ibm.db2.jcc.b.SqlException: Invalid argument: unknown column name COL1 when trying to access my resultSet with rs.getString("COL1").
My SQL Query is: Select UPPER(COL1) from table1.
the same query and Java code is working fine with DB2 v8(Type 2 driver) but it is throwing the above exception when using with DB2 v9(Type 4 driver).

However i am able to resolve this error by adding an alias,
modified query: Select UPPER(COL1) COL1 from table1.

the above query is working with both DB2 v8 and v9.
does this mean, in DB2 9 we must provide an alias when using with functions like (upper,trim,..)???

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆で 2024-08-19 02:34:52

DB2 或 SQL 中没有任何内容要求函数的列名是特定值。

可能是早期的驱动程序(甚至是 t2 驱动程序,我通常不再使用它,我自己更喜欢 t4)给了你一个你期望的列名,但我想知道它会给你什么 col1 | '.' |列2

您的查询确实应该是您必须让它工作的:

select upper(col1) as col1 from table1

这保证了列名称是col1

如果您确实想知道查询的列名称是什么,您可以使用以下调用检索结果集的元数据(仅示例):

ResultSet rs = <get your result set here>;
ResultSetMeatData meta = rs.getMetaData();
for (int i = 1; i < meta.getColumnCount(); i++) {
    System.out.println (getColumnName (i));
}

但是您应该使用 as 子句来确保名称符合预期。

Nothing in DB2 or SQL requires the column names of functions to be specific values.

It may be that the earlier drivers (or even the t2 drivers, which I would generally never use anymore, preferring t4 myself) gave you a column name you expected but I wonder what it would have given you for col1 | '.' | col2.

Your query really should be what you have to get it working:

select upper(col1) as col1 from table1

This guarantees the column name is col1.

If you really want to know what the column names are for your query, you can retrieve the meta data for the result set with the following calls (examples only):

ResultSet rs = <get your result set here>;
ResultSetMeatData meta = rs.getMetaData();
for (int i = 1; i < meta.getColumnCount(); i++) {
    System.out.println (getColumnName (i));
}

But you should be using the as clause to ensure the names are as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文