我得到了以下錯誤在測試一些代碼:什麼是以下Oracle錯誤意思是:無效的列索引
SQLException: Invalid column index
究竟是什麼意思呢?
是否有在線文檔解釋所有Oracle錯誤代碼和語句?
我得到了以下錯誤在測試一些代碼:什麼是以下Oracle錯誤意思是:無效的列索引
SQLException: Invalid column index
究竟是什麼意思呢?
是否有在線文檔解釋所有Oracle錯誤代碼和語句?
如果這是Java引發的SQLException,那很可能是因爲您試圖從ResultSet獲取或設置值,但是您使用的索引不在該範圍內。
例如,您可能試圖從結果集中獲取索引3處的列,但只有兩列從SQL查詢返回。
這聽起來像你想SELECT
列不存在。
也許你想ORDER BY
列不存在?
SQL語句中的任何拼寫錯誤?
使用Spring的SimpleJdbcTemplate進行,我得到了它,當我試圖做到這一點:
String sqlString = "select pwy_code from approver where university_id = '123'";
List<Map<String, Object>> rows = getSimpleJdbcTemplate().queryForList(sqlString, uniId);
我有一個參數的queryForList未對應於SQL問號。第一行應該是:
String sqlString = "select pwy_code from approver where university_id = ?";
我使用Spring Security的3.1.0當有完全相同的問題。和Oracle 11G。我用下面的查詢和獲取無效列索引錯誤:
<security:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT A.user_name AS username, A.password AS password FROM MB_REG_USER A where A.user_name=lower(?)"
事實證明,我需要添加:「1爲啓用」來查詢:
<security:jdbc-user-service data-source-ref="dataSource" users-by-username query="SELECT A.user_name AS username, A.password AS password, 1 as enabled FROM MB_REG_USER A where A.user_name=lower(?)"
一切的工作之後。我相信這可能是Spring JDBC核心包中的一個錯誤...
我有使用準備語句的這個問題。我沒有添加足夠的「?」對於「價值」我的日食已經崩潰後,我添加了適當的金額,並失去了這些變化。但是直到我開始通過p.campbell提出的SQL來梳理SQL之後,我才意識到這是錯誤的。
我也有這種類型的錯誤,問題是參數聲明類似錯誤的用法,比方說,你有這樣的
SELECT * FROM EMPLOYE E WHERE E.ID = ?
和PreparedStatement對象(JDBC)查詢,如果你設置的參數,如
preparedStatement.setXXX(1,value);
preparedStatement.setXXX(2,value)
然後它會導致SQLException: Invalid column index
所以,我刪除了第二個參數設置到準備好的語句,然後問題解決了
我在一個遺留應用程序中動態創建預處理語句時遇到了這個問題。
String firstName;
StringBuilder query =new StringBuilder("select id, name from employee where country_Code=1");
query.append("and name like '");
query.append(firstName + "' ");
query.append("and ssn=?");
PreparedStatement preparedStatement =new prepareStatement(query.toString());
當它嘗試爲ssn設置值時,它給出了無效的列索引錯誤,最後發現它是由firstName具有'within;干擾語法。
我有Oracle表下面的結構
SQL> desc demo
Name Null? Type
----------------------------------------- -------- ------------
ID NUMBER(38)
NAME VARCHAR2(20)
SALARY NUMBER(6)
****************************
我試圖用下面的代碼中插入值,並得到了錯誤
****************************
PreparedStatement stmt=con.prepareStatement("update demo set salary=? where id=?");
stmt.setInt(3,288800);
stmt.setInt(1,8);
************************
的SQLException:無效的列索引
正確的代碼
************************
PreparedStatement stmt=con.prepareStatement("update demo set salary=? where id=?");
stmt.setInt(1,288800);
stmt.setInt(2,8);
*******************
stmt.setInt(1,288800);//1 represents salary i.e first '?'
stmt.setInt(2,8);//2 represents id i.e second '?'
這裏1實際上在preparestatement查詢的數據庫表列代表不無柱無
希望這有助於..
[1]: https://i.stack.imgur.com/vXvMA.png
最終的SQL語句是一樣的東西:
select col_1 from table_X where col_2 = 'abcd';
我運行這在我的SQL IDE裏面,一切正常。
接下來,我嘗試建立這一說法與Java:
String queryString= "select col_1 from table_X where col_2 = '?';";
PreparedStatement stmt = con.prepareStatement(queryString);
stmt.setString(1, "abcd"); //raises java.sql.SQLException: Invalid column index
雖然SQL語句(第一個,跑了針對數據庫)包含字符串值的引號,也完成了semicolumn時,我傳遞給PreparedStatement的字符串不應包含通配符周圍的引號,也不應以半列結束。
我只除去出現在白色背景中的字符
"select col_1 from table_X where col_2 =
'?
';";
獲得
"select col_1 from table_X where col_2 = ?";
(我發現這裏的解決方案:https://coderanch.com/t/424689/databases/java-sql-SQLException-Invalid-column)
您可以編輯您的問題,包括確切的SQL語句,這個錯誤扔?也許包括確切的錯誤細節以及ORA編號? –
Oracle錯誤消息:http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/toc.htm –