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
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 ) + ")";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With