Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORA-00911: invalid character error using a PreparedStatement

Tags:

java

I am trying to pass the list of order numbers in where clause using Prepared Stmt. I am getting the error as Invalid character . Using the below code

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

ERROR: java.sql.SQLException: ORA-00911: invalid character

Could someone help in fixing it

like image 418
Yuvaraj M Avatar asked Mar 18 '23 19:03

Yuvaraj M


1 Answers

The invalid character is the semi colon at the end of your sql.

Change this line:

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

to

sql = sql.substring( 0, sql.length()-1  ) + ")";
like image 91
James Hutchinson Avatar answered Apr 02 '23 22:04

James Hutchinson