以下 Oracle 错误是什么意思:无效的列索引
我在测试一些代码时遇到以下错误:
SQLException:无效的列索引
到底是什么意思?
有没有在线文档解释所有Oracle错误代码和语句?
I got the following error while testing some code:
SQLException: Invalid column index
What exactly does that mean?
Is there an online document explaining what all the Oracle error codes and statements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我在使用 Spring Security 3.1.0 时遇到了完全相同的问题。和甲骨文11G。我正在使用以下查询并收到无效的列索引错误:
事实证明,我需要在查询中添加:“1 asenabled”:
此后一切正常。我相信这可能是 Spring JDBC 核心包中的一个错误......
I had the exact same problem when using Spring Security 3.1.0. and Oracle 11G. I was using the following query and getting the invalid column index error:
It turns out that I needed to add: "1 as enabled" to the query:
Everything worked after that. I believe this could be a bug in the Spring JDBC core package...
最终的 sql 语句类似于:
我在 SQL IDE 中运行它,一切正常。
接下来,我尝试使用 java 构建此语句:
虽然 sql 语句(第一个针对数据库运行的语句)包含字符串值周围的引号,并且还以半列结束,但我传递给PreparedStatement 的字符串不应包含引号围绕通配符 ? ,也不应该以半栏结束。
我刚刚删除了白色背景上出现的字符
"select col_1 from table_X where col_2 =
'?
' ;";
获取
(我在这里找到了解决方案:https://coderanch.com/t/424689/databases/java-sql-SQLException-Invalid-column)
the final sql statement is something like:
i run this inside my SQL IDE and everything is ok.
Next, i try to build this statement with java:
Although the sql statement (the first one, ran against the database) contains quotes around string values, and also finishes with a semicolumn, the string that i pass to the PreparedStatement should not contain quotes around the wildcard character ?, nor should it finish with semicolumn.
i just removed the characters that appear on white background
"select col_1 from table_X where col_2 =
'?
' ;";
to obtain
(i found the solution here: https://coderanch.com/t/424689/databases/java-sql-SQLException-Invalid-column)
我在一个动态创建准备好的语句的遗留应用程序中遇到了这个问题。
当它尝试为ssn设置值时,它给出了无效的列索引错误,最后发现这是由于firstName中包含'引起的;扰乱语法。
I had this problem in one legacy application that create prepared statement dynamically.
when it try to set value for ssn, it was giving invalid column index error, and finally found out that it is caused by firstName having ' within; that disturb the syntax.
如果这是 Java 抛出的 SQLException,则很可能是因为您尝试从 ResultSet 获取或设置值,但您使用的索引不在范围内。
例如,您可能尝试从结果集中获取索引 3 处的列,但 SQL 查询只返回两列。
If that's a SQLException thrown by Java, it's most likely because you are trying to get or set a value from a ResultSet, but the index you are using isn't within the range.
For example, you might be trying to get the column at index 3 from the result set, but you only have two columns being returned from the SQL query.
听起来您正在尝试
SELECT
一个不存在的列。也许您正在尝试
ORDER BY
一个不存在的列?您的 SQL 语句中是否有拼写错误?
It sounds like you're trying to
SELECT
a column that doesn't exist.Perhaps you're trying to
ORDER BY
a column that doesn't exist?Any typos in your SQL statement?
使用 Spring 的 SimpleJdbcTemplate,当我尝试执行此操作时,我得到了它:
我有一个 queryForList 的参数,该参数与 SQL 中的问号不对应。第一行应该是:
Using Spring's SimpleJdbcTemplate, I got it when I tried to do this:
I had an argument to queryForList that didn't correspond to a question mark in the SQL. The first line should have been:
我也遇到了这种类型错误,问题是对语句的参数使用错误,例如,假设您有一个这样的查询,
并且对于准备好的语句对象(JDBC),如果您设置像这样的参数
,那么它会导致 SQLException:无效列因此
,我删除了准备好的语句的第二个参数设置,然后问题就解决了
I also got this type error, problem is wrong usage of parameters to statement like, Let's say you have a query like this
and for the preparedStatement object (JDBC) if you set the parameters like
then it results in
SQLException: Invalid column index
So, I removed that second parameter setting to prepared statement then problem solved
只需尝试此修复,因为我遇到了您的错误:
删除问号周围的单引号,这意味着,如果您使用了保留参数,例如 ('?','?','?' )你应该让它看起来像这样:
Just try this fix, as I faced your error:
Remove the single quotation marks around your question mark, which means, if you used your reserved parameters like ('?','?','?') you should make it look like this:
我使用准备好的声明时遇到了这个问题。我没有添加足够的“?”对于“VALUES”,在我添加适当的数量后,我的日食崩溃了,并丢失了这些更改。但直到我按照 p.campbell 的建议开始梳理 SQL 时,我才意识到这是错误。
I had this problem using a prepared statement. I didn't add enough "?" for the "VALUES" My eclipse had crashed after I did add the proper amount, and lost those changes. But that didn't occur to me to be the error until I started combing through the SQL as p.campbell suggested.