Buggy code:
public class InvoicedetailsDao { public InvoicedetailsDao ( ) { } public JSONObject SummarySalePDF ( String invoiceId , String invoiceDateFrom , String invoiceDateTo , String brandName , String model , String cusName , UserDetailsBean userBean ) { } public JSONObject InvoiceSalePDF ( String invoiceId , UserDetailsBean userBean ) { System . out . println ( "[InvoicedetailsDao][InvoiceSalePDF][Begin]" ) ; String sql = null ; ResultSet rs = null ; JSONObject jsonObjectDetail = null ; String cusCode = "" ; String flagAddSales = "" ; String invoiceIdAddSales = "" ; EnjoyConectDbs db = null ; try { db = new EnjoyConectDbs ( ) ; <START_BUG> sql = ( ( "<seq2seq4repair_space>select<seq2seq4repair_space>t.*<seq2seq4repair_space>from<seq2seq4repair_space>(select<seq2seq4repair_space>i.invoiceId<seq2seq4repair_space>invoiceId" + ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(c.cusName,<seq2seq4repair_space>'<seq2seq4repair_space>',<seq2seq4repair_space>c.cusSurname)<seq2seq4repair_space>cusName" + "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(c.houseNumber,<seq2seq4repair_space>'<seq2seq4repair_space>หมู่ที่<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>c.mooNumber,<seq2seq4repair_space>'<seq2seq4repair_space>ถนน<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>c.streetName,<seq2seq4repair_space>'<seq2seq4repair_space>ตำบล<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>i.EngineNoDisp,<seq2seq4repair_space>'<seq2seq4repair_space>อำเภอ<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>i.EngineNoDisp,<seq2seq4repair_space>'<seq2seq4repair_space>จังหวัด<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>i.EngineNoDisp<seq2seq4repair_space>)<seq2seq4repair_space>cusAddress" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>b.brandName<seq2seq4repair_space>brandName" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>m.model<seq2seq4repair_space>model" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(m.chassis,<seq2seq4repair_space>i.chassisDisp<seq2seq4repair_space>)<seq2seq4repair_space>chassisDisp" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(m.engineNo,i.EngineNoDisp<seq2seq4repair_space>)<seq2seq4repair_space>EngineNoDisp" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.color<seq2seq4repair_space>color" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.size<seq2seq4repair_space>size" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.priceAmount<seq2seq4repair_space>priceAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.vatAmount<seq2seq4repair_space>vatAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.totalAmount<seq2seq4repair_space>totalAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.commAmount<seq2seq4repair_space>commAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.invoiceDate<seq2seq4repair_space>invoiceDate" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.remark<seq2seq4repair_space>remark" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.cusCode<seq2seq4repair_space>cusCode" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>c.idNumber<seq2seq4repair_space>idNumber" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.flagAddSales<seq2seq4repair_space>flagAddSales" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.invoiceIdAddSales<seq2seq4repair_space>invoiceIdAddSales" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.flagCredit<seq2seq4repair_space>flagCredit" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.creditAmount<seq2seq4repair_space>creditAmount" ) + "<seq2seq4repair_space>from<seq2seq4repair_space>invoicedetails<seq2seq4repair_space>i,<seq2seq4repair_space>customer<seq2seq4repair_space>c,<seq2seq4repair_space>motorcyclesdetails<seq2seq4repair_space>m,<seq2seq4repair_space>branddetails<seq2seq4repair_space>b" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>c.cusCode<seq2seq4repair_space>=<seq2seq4repair_space>i.cusCode" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>m.motorcyclesCode<seq2seq4repair_space>=<seq2seq4repair_space>i.motorcyclesCode" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>b.brandCode<seq2seq4repair_space>=<seq2seq4repair_space>m.brandCode)<seq2seq4repair_space>t<seq2seq4repair_space>where<seq2seq4repair_space>1=1<seq2seq4repair_space>" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>t.invoiceId<seq2seq4repair_space>=<seq2seq4repair_space>'" ) ) + invoiceId ) + "'" ; <END_BUG> System . out . println ( ( "[InvoicedetailsDao][InvoiceSalePDF]<seq2seq4repair_space>sql<seq2seq4repair_space>::<seq2seq4repair_space>" + sql ) ) ; rs = db . executeQuery ( sql ) ; while ( rs . next ( ) ) { jsonObjectDetail = new JSONObject ( ) ; jsonObjectDetail . put ( "invoiceId" , EnjoyUtils . nullToStr ( rs . getString ( "invoiceId" ) ) ) ; jsonObjectDetail . put ( "invoiceDate" , EnjoyUtils . displayDateThai ( rs . getString ( "invoiceDate" ) ) ) ; cusCode = rs . getString ( "cusCode" ) ; flagAddSales = rs . getString ( "flagAddSales" ) ; invoiceIdAddSales = rs . getString ( "invoiceIdAddSales" ) ; jsonObjectDetail . put ( "cusNameDisp" , EnjoyUtils . nullToStr ( rs . getString ( "cusName" ) ) ) ; jsonObjectDetail . put ( "idNumber" , EnjoyUtils . nullToStr ( rs . getString ( "idNumber" ) ) ) ; jsonObjectDetail . put ( "brandName" , EnjoyUtils . nullToStr ( rs . getString ( "brandName" ) ) ) ; jsonObjectDetail . put ( "model" , EnjoyUtils . nullToStr ( rs . getString ( "model" ) ) ) ; jsonObjectDetail . put ( "chassisDisp" , EnjoyUtils . nullToStr ( rs . getString ( "chassisDisp" ) ) ) ; jsonObjectDetail . put ( "engineNoDisp" , EnjoyUtils . nullToStr ( rs . getString ( "engineNoDisp" ) ) ) ; jsonObjectDetail . put ( "color" , EnjoyUtils . nullToStr ( rs . getString ( "color" ) ) ) ; jsonObjectDetail . put ( "size" , EnjoyUtils . nullToStr ( rs . getString ( "size" ) , "0" ) ) ; jsonObjectDetail . put ( "priceAmount" , EnjoyUtils . convertFloatToDisplay ( EnjoyUtils . nullToStr ( rs . getString ( "priceAmount" ) , "0" ) , 2 ) ) ; jsonObjectDetail . put ( "vatAmount" , EnjoyUtils . convertFloatToDisplay ( EnjoyUtils . nullToStr ( rs . getString ( "vatAmount" ) , "0" ) , 2 ) ) ; jsonObjectDetail . put ( "totalAmount" , EnjoyUtils . convertFloatToDisplay ( EnjoyUtils . nullToStr ( rs . getString ( "totalAmount" ) , "0" ) , 2 ) ) ; jsonObjectDetail . put ( "totalAmountThai" , EnjoyUtils . displayAmountThai ( EnjoyUtils . nullToStr ( rs . getString ( "totalAmount" ) , "0" ) ) ) ; jsonObjectDetail . put ( "remark" , EnjoyUtils . nullToStr ( rs . getString ( "remark" ) ) ) ; jsonObjectDetail . put ( "CompanyName" , userBean . getCompanyName ( ) ) ; jsonObjectDetail . put ( "tel" , userBean . getTel ( ) ) ; jsonObjectDetail . put ( "CompanyAddress" , userBean . getCompanyAddress ( ) ) ; jsonObjectDetail . put ( "branchName" , userBean . getBranchName ( ) ) ; jsonObjectDetail . put ( "tin" , userBean . getTin ( ) ) ; jsonObjectDetail . put ( "invoiceIdAddSales" , EnjoyUtils . nullToStr ( rs . getString ( "invoiceIdAddSales" ) ) ) ; jsonObjectDetail . put ( "flagAddSales" , rs . getString ( "flagAddSales" ) ) ; jsonObjectDetail . put ( "commAmount" , EnjoyUtils . convertFloatToDisplay ( EnjoyUtils . nullToStr ( rs . getString ( "commAmount" ) , "0" ) , 2 ) ) ; jsonObjectDetail . put ( "flagCredit" , rs . getString ( "flagCredit" ) ) ; jsonObjectDetail . put ( "creditAmount" , EnjoyUtils . convertFloatToDisplay ( EnjoyUtils . nullToStr ( rs . getString ( "creditAmount" ) , "0" ) , 2 ) ) ; jsonObjectDetail . put ( "creditAmountThai" , EnjoyUtils . displayAmountThai ( EnjoyUtils . nullToStr ( rs . getString ( "creditAmount" ) , "0" ) ) ) ; } if ( ! ( cusCode . equals ( "" ) ) ) { jsonObjectDetail . put ( "cusAddress" , findCustomerById ( cusCode ) ) ; } if ( flagAddSales . equals ( "Y" ) ) { InvoiceAddSalesPDF ( invoiceIdAddSales , jsonObjectDetail ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { db . setDisconnection ( rs ) ; System . out . println ( "[InvoicedetailsDao][InvoiceSalePDF][End]" ) ; } return jsonObjectDetail ; } private String findCustomerById ( String cusCode ) { } public void InvoiceAddSalesPDF ( String invoiceIdAddSales , JSONObject jsonObjectDetail ) { } }

Fix:
sql = ( ( "<seq2seq4repair_space>select<seq2seq4repair_space>t.*<seq2seq4repair_space>from<seq2seq4repair_space>(select<seq2seq4repair_space>i.invoiceId<seq2seq4repair_space>invoiceId" + ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(c.cusName,<seq2seq4repair_space>'<seq2seq4repair_space>',<seq2seq4repair_space>c.cusSurname)<seq2seq4repair_space>cusName" + "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(c.houseNumber,<seq2seq4repair_space>'<seq2seq4repair_space>หมู่ที่<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>c.mooNumber,<seq2seq4repair_space>'<seq2seq4repair_space>ถนน<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>c.streetName,<seq2seq4repair_space>'<seq2seq4repair_space>ตำบล<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>i.EngineNoDisp,<seq2seq4repair_space>'<seq2seq4repair_space>อำเภอ<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>i.EngineNoDisp,<seq2seq4repair_space>'<seq2seq4repair_space>จังหวัด<seq2seq4repair_space>'<seq2seq4repair_space>,<seq2seq4repair_space>i.EngineNoDisp<seq2seq4repair_space>)<seq2seq4repair_space>cusAddress" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>b.brandName<seq2seq4repair_space>brandName" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>m.model<seq2seq4repair_space>model" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(m.chassis,<seq2seq4repair_space>i.chassisDisp<seq2seq4repair_space>)<seq2seq4repair_space>chassisDisp" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>CONCAT(m.engineNo,i.EngineNoDisp<seq2seq4repair_space>)<seq2seq4repair_space>EngineNoDisp" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.color<seq2seq4repair_space>color" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.size<seq2seq4repair_space>size" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.priceAmount<seq2seq4repair_space>priceAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.vatAmount<seq2seq4repair_space>vatAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.totalAmount<seq2seq4repair_space>totalAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.commAmount<seq2seq4repair_space>commAmount" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.invoiceDate<seq2seq4repair_space>invoiceDate" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.remark<seq2seq4repair_space>remark" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.cusCode<seq2seq4repair_space>cusCode" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>c.idNumber<seq2seq4repair_space>idNumber" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.flagAddSales<seq2seq4repair_space>flagAddSales" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.invoiceIdAddSales<seq2seq4repair_space>invoiceIdAddSales" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.flagCredit<seq2seq4repair_space>flagCredit" ) + "<seq2seq4repair_space>,<seq2seq4repair_space>i.creditTotalAmount<seq2seq4repair_space>creditAmount" ) + "<seq2seq4repair_space>from<seq2seq4repair_space>invoicedetails<seq2seq4repair_space>i,<seq2seq4repair_space>customer<seq2seq4repair_space>c,<seq2seq4repair_space>motorcyclesdetails<seq2seq4repair_space>m,<seq2seq4repair_space>branddetails<seq2seq4repair_space>b" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>c.cusCode<seq2seq4repair_space>=<seq2seq4repair_space>i.cusCode" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>m.motorcyclesCode<seq2seq4repair_space>=<seq2seq4repair_space>i.motorcyclesCode" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>b.brandCode<seq2seq4repair_space>=<seq2seq4repair_space>m.brandCode)<seq2seq4repair_space>t<seq2seq4repair_space>where<seq2seq4repair_space>1=1<seq2seq4repair_space>" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>t.invoiceId<seq2seq4repair_space>=<seq2seq4repair_space>'" ) ) + invoiceId ) + "'" ;