繁体   English   中英

SQL-Java:无效的列名:无效的列名

[英]SQL - Java : Invalid column name :Invalid column name

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();
    }

错误:

[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

您不需要在NOC周围使用双引号引起来:

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

您对外部字符串的定界符是双引号,因此无需转义单引号。

列名不需要''

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);

这应该起作用了。

sb.append(“和T1.OU_TYPE_CD <>'NOC'”);

您确定收到相同的错误消息吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM