ORA-00911:使用PreparedStatement时出现无效字符错误

时间:2014-11-27 11:33:57

标签: java

我正在尝试使用Prepared Stmt传递where子句中的订单号列表。我收到错误为无效字符。使用以下代码

        List<String> ordernolist = Arrays.asList(orderno.split(","));


        String sql = "select * from ORDER_"+Market+".MARC_ORD_UN_STS_T s,ORDER_"+Market+".MARC_ORD_LN_T l, "
                + "ORDER_"+Market+".MARC_ORD_T o ,ORDER_"+Market+".ORD_RLS_REL_T ort,ORDER_"+Market+".RLS_T rt,ORDER_"+Market+".RLS_LN_T rn "
                + "where RT.RLS_KEY=RN.RLS_KEY and O.MARC_ORD_KEY=L.MARC_ORD_KEY and L.MARC_ORD_LN_KEY=S.MARC_ORD_LN_KEY and "
                + "O.ORD_NO=ORT.ORD_NBR and ORT.CRM_ORD_NBR=RT.CRM_ORD_NBR and "
                //+ "S.MARC_ORD_STS_CD='500' and "
                + "RN.LN_QTY>0 and RN.ORIG_ORD_LN_NBR=L.ORD_LN_NBR and s.sts_qty>0 "
                + "and O.ORD_NO in (";
        for( String id : ordernolist ){
                    sql += "?,";
                }
                sql = sql.substring( 0, sql.length()-1  ) + ");";
        //System.out.println(sql);


         PreparedStatement preparedStatement = OmsConn.prepareStatement(sql);

         for( int ono = 0; ono < ordernolist.size(); ono++ ){
             preparedStatement.setString(ono+1, ordernolist.get(ono));
            }

错误:java.sql.SQLException:ORA-00911:无效字符

有人可以帮忙修理它

1 个答案:

答案 0 :(得分:4)

无效字符是sql末尾的半冒号。

更改此行:

sql = sql.substring( 0, sql.length()-1  ) + ");";

sql = sql.substring( 0, sql.length()-1  ) + ")";