简体   繁体   中英

Cannot update data in oracle database using java

I'm trying to update the data from my oracle database using this code. The program has no error but it display ORA-00933: SQL command not properly ended .
Can anyone let me know what does it mean and how can I correct it?

String gdta="
  UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR' 
    WHERE CLIENT_ADDRESS4 = 68100 BATU CAVES SELANGOR D.E. 
UNION 
  UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR' 
    WHERE CLIENT_ADDRESS4 = 47100 PUCHONG,SELANGORUNION 
  UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR'
    WHERE CLIENT_ADDRESS4 = 47100 PUCHONG";

You can't combine update statements in a union statement. Also it looks like you need to quote the client_address4 values.

Try running your SQL command in a SQL client before trying it in java and see if it works.

I think you need to execute multiple statements, instead of a single one, like this:

String gdta="UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR' WHERE CLIENT_ADDRESS4 = '68100 BATU CAVES SELANGOR D.E.'";
String gdta2="UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR' WHERE CLIENT_ADDRESS4 = '47100 PUCHONG,SELANGOR'";
String gdta3="UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR' WHERE CLIENT_ADDRESS4 = '47100 PUCHONG'";

or, use a single statement with an in-clause:

String gdta="UPDATE CLIENT_DATA SET CLIENT_ADDRESS4 = 'SELANGOR' WHERE CLIENT_ADDRESS4 in ('68100 BATU CAVES SELANGOR D.E.', '47100 PUCHONG,SELANGOR', '47100 PUCHONG')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM