2014-01-24 65 views
0
protected String getSQLCarFinder() 
{ 
    StringBuffer sb = new StringBuffer(); 
    sb.append("select distinct T1.ASSET_AMT c1, T1.NAME c2, T1.ALIAS_NAME c3 "); 
    sb.append("from {0}.CARFINDERDB T1 "); 
    sb.append("where T1.ASSET_AMT=? "); 
    sb.append(" and T1.OU_TYPE_CD <> ''NOC'' "); 
    sb.append(" and " + IRDataSource.getLengthFunctionName() + "(T1.ASSET_AMT) <= " + CARFINDER_CODE_MAX_LENGTH); 
    return sb.toString(); 
    } 

錯誤:SQL - Java的:無效的列名:無效的列名

[2014-01-24 10:42:20,238] Thread-66 ERROR util.XNAMEDbLogProcessor - XNAMEDbLogProcessor :: logItem : ExceptionAn unexpected token "NOC" was found following "nvalid column name '". Expected tokens may include: ",".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.7.112 
[2014-01-24 10:42:20,238] Thread-66 ERROR util.XNAMEDbLogProcessor - XNAMEDbLogProcessor :: logItem : An error occurred while logging data to the database: An unexpected token "NOC" was found following "nvalid column name '". Expected tokens may include: ",".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.7.112: Data={[2014-01-24-10.42.17.318000] [server_common_name] [common_name] [] [99999] [0] [] [] [] [E] [INTRANET] [2014-01-24] [10:42:20] [CDLT] [Account : com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'NOC'.] } 
[2014-01-24 10:42:22,458] RMI TCP Connection(98501)-172.28.24.27 DEBUG dataaccess.NewCarViewDataSource - NewCarViewDataSource:: connect : IR connect siebel without user and password 
[2014-01-24 10:42:22,477] RMI TCP Connection(98501)-172.28.24.27 DEBUG dataaccess.IRDataSource - IRDataSource:: getLengthFunctionName : Lenght function name:LEN 
[2014-01-24 10:42:22,478] RMI TCP Connection(98501)-172.28.24.27 ERROR server.AssociateCodeListRetrieveCommand - AssociateCodeListRetrieveCommand ::executeINTRANETCall : Exception Invalid column name 'NOC'. 
[2014-01-24 10:42:22,481] RMI TCP Connection(98501)-172.28.24.27 DEBUG server.REPDatabaseCommand - REPDatabaseCommand :: executeCall : Time to execute CDLT transaction = 23 
[2014-01-24 10:42:23,144] Thread-65 DEBUG util.XNAMEAlertLogProcessor - XNAMEAlertLogProcessor :: logItem : Error alert log processor: ALERT-001 -s "Error occurred in AssociateCodeListInfo" Date:  Time: Server name: server_common_name Client name: common_name 


User id: **strong text** 

我試圖

sb.append(" and T1.OU_TYPE_CD <> /'NOC/' "); 
sb.append(" and T1.OU_TYPE_CD <> ''NOC'' "); 
sb.append(" and T1.OU_TYPE_CD <> 'NOC' "); 

沒有工作。我在這裏做錯了什麼? T1.OU_TYPE_CD是列名,NOC是其中的值。我想檢查T1.OU_TYPE_CD的值是NOT NOC

+1

你能打印出字符串嗎? –

+0

你確定問題出在那裏嗎?那之後呢? –

回答

0

你不需要雙單引號括起來NOC

sb.append(" and T1.OU_TYPE_CD <> 'NOC' "); 

您的外字符串分隔符是一個雙引號,所以沒有必要逃避單引號。

+0

試過,不工作! – user3232895

+0

@ user3232895。 。 。它不應該是同一個錯誤,因爲在這個查詢中'NOC'不能是列名。 –

+0

@ Lionoff ......不幸的是同樣的錯誤。無效的列名稱NOC! – user3232895

0

列名不需要''

sb.append(" and T1.OU_TYPE_CD <> NOC "); 

編輯:

編譯器被解釋爲NOC列名。如果NOCstring值,我認爲您的問題將是一個轉義問題。

嘗試:

sb.append(" and T1.OU_TYPE_CD <> \'NOC\' ");

或本:

sb.append(" and T1.OU_TYPE_CD NOT IN ('NOC') ");

或直接設置一個aux字符串:

String aux = " and T1.OU_TYPE_CD <> 'NOC' "; 
sb.append(aux); 
+0

它不是列名,NOC是T1.OU_TYPE_CD列中的數據 – user3232895

0

這應該有工作。 ''和'。''''''');;

您確定您收到相同的錯誤訊息嗎?