I'm using the following method to run a prepared sql statement in java, but it give me an syntax error message:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update temp_test inner join ups_bill on temp_test.tracking_number=ups_bill.tra' at line 6
can some one point out what might be wrong please? Very much appreciated!
Here the code for the method:
private void updateTemp(){
try{
String sql="insert into temp_test (tracking_number, account_number, service, to_name, to_address, to_city, to_state, to_zip, to_zone, invoice_number, invoice_date, ship_date, account_code,entry_type_1,entry_type_2) \n" +
"select distinct trackingnumber1, AccountNumber, chargetypedescription, receiverorganization, receiveraddressline1, receivercity, receiverstate, receiverzipcode, zone, invoicenumber, invoicedate, pickupdate, mid(ref4,1,3),entrytype, entrytype2 \n" +
"from ups_bill \n" +
"where trackingnumber1!= ' ' and ChargeType = 'FRT' and entrytype = 'SHP' and entrycategorycode!='DFC' and entrycategorycode!='DTP' \n" +
"and not exists (select * from temp_test where temp_test.tracking_number=trackingnumber1 and temp_test.invoice_date=invoicedate);\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 \n" +
"set temp_test.account_code=mid(ups_bill.ref2,1,3) \n" +
"where mid(temp_test.account_code,1,1) between 'a' and 'z';\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 \n" +
"set temp_test.account_code=mid(ups_bill.ref1,1,3) \n" +
"where mid(temp_test.account_code,1,1) \n" +
"between 'a' and 'z';\n" +
"update temp_test \n" +
"inner join customer_account \n" +
"on temp_test.account_code=customer_account.customer_code \n" +
"set temp_test.customer_name=\"Dyson Inc\";\n" +
"update temp_test \n" +
"inner join customer_info \n" +
"on temp_test.customer_name=customer_info.customer_name \n" +
"set temp_test.address=customer_info.address_line_1;\n" +
"update temp_test \n" +
"inner join customer_info \n" +
"on temp_test.customer_name=customer_info.customer_name \n" +
"set temp_test.addressline2=customer_info.address_line_2;\n" +
"update temp_test \n" +
"inner join customer_info \n" +
"on temp_test.customer_name=customer_info.customer_name \n" +
"set temp_test.city=customer_info.city;\n" +
"update temp_test \n" +
"inner join customer_info \n" +
"on temp_test.customer_name=customer_info.customer_name \n" +
"set temp_test.state=customer_info.state;\n" +
"update temp_test \n" +
"inner join customer_info \n" +
"on temp_test.customer_name=customer_info.customer_name \n" +
"set temp_test.zip_code=customer_info.zip_code;\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 \n" +
"set temp_test.ref_two=if(ups_bill.ref2!='',ups_bill.ref2,null);\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 \n" +
"set temp_test.ref_one=if(ups_bill.ref1!='',ups_bill.ref1,'');\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 \n" +
"and ups_bill.chargetype=\"FRT\" \n" +
"set temp_test.ups_charge=ups_bill.incentivecredit+ups_bill.billedcharge;\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 and ups_bill.chargetype=\"FSC\" \n" +
"set temp_test.acc_charges=ups_bill.chargeamount-temp_test.ups_charge;\n" +
"update temp_test \n" +
"inner join ups_bill \n" +
"on temp_test.tracking_number=ups_bill.trackingnumber1 and ups_bill.chargetype=\"FSC\" \n" +
"set temp_test.fsc=ups_bill.incentivecredit+ups_bill.billedcharge;\n" +
"update temp_test \n" +
"inner join customer_discount \n" +
"on temp_test.customer_name=customer_discount.customer_name \n" +
"and temp_test.service=customer_discount.service \n" +
"set temp_test.discount=customer_discount.discount;\n" +
"update temp_test \n" +
"inner join customer_discount \n" +
"on temp_test.customer_name=customer_discount.customer_name and temp_test.service=customer_discount.service \n" +
"set temp_test.min_charge=customer_discount.min_charge;\n" +
"update temp_test \n" +
"set temp_test.incentives=if(temp_test.ups_charge*(1-temp_test.discount)>=temp_test.min_charge,temp_test.ups_charge*temp_test.discount,temp_test.ups_charge-temp_test.min_charge);\n" +
"update temp_test \n" +
"set temp_test.billed_charges=temp_test.ups_charge-temp_test.incentives+temp_test.acc_charges+fsc;";
pst=conn.prepareStatement(sql);
pst.executeUpdate();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}