Link to home
Start Free TrialLog in
Avatar of jhughes4
jhughes4

asked on

Update Oracle from Java

Can someone clarify something for me?  I have a method that's suppose to do updates, with the calling application passing the actual Update string.  The syntax I'm trying to use is the following:

stmt.executeQuery(Query);

where Query = "UPDATE TABLE SET COLUMN = 'newvalue' where COLUMN2 = 'NEXTVALUE'"

By the way the database is Oracle, but the update doesn't happen.  I verified the update statement in SQL PLUS....

thanks in advance!
Avatar of Mick Barry
Mick Barry
Flag of Australia image

> stmt.executeQuery(Query);

should be:

stmt.executeUpdate(Query);
Avatar of jhughes4
jhughes4

ASKER

I did try that, but I think I found the actual problem... The SQL statement being passed is the following not what I originally posted, sorry:

"UPDATE TABLE SET COLUMN1 = 'NEWVALUE' WHERE COLUMN1 = 'OLDVALUE'

I've looked in the database and there are multiple rows that contain the 'NEWVALUE' in COLUMN1.  When I execute this query, I don't get an exception, but the database isn't updated either....what should I do in this situation??

thanks again
whats the return value from the above call?
Nothing.  Should I be using a ResultSet to loop through the return?
What do you mean by nothing? It returns a value indicating the number of rows updated.
Sorry 2.
That indicates it *has* updated two rows.

> I've looked in the database and there are multiple rows that contain the 'NEWVALUE' in COLUMN1

Thats what the column would contain if updated using the above query.
That's correct, but when I execute a select statement from SQL PLUS, the updates don't show.  The 'oldvalues' are still there.
I'm confused?  Above you said:
"I've looked in the database and there are multiple rows that contain the 'NEWVALUE' in COLUMN1"

How are you looking into the database in this case.
And are you saying if you look using SQL PLUS then the same rows contain 'OLDVALUE'?
Sorry let's try this again....

Say I have a table

COLUMN1     COLUMN2
DATA            SOMEOTHERDATA
DATA            YETSOMEMOREDATA
DATA2          LASTONE

If I execute the following update from the Java program, it returns a value of 2, but when I review the database via SQL PLUS, the table looks as though it hasn't been updated.
UPDATE TABLE SET COLUMN1 = 'NEWDATA' WHERE COLUMN1 = 'DATA'

However if I execute the query
UPDATE TABLE SET COLUMN1 = 'NEWDATA' WHERE COLUMN2 = 'SOMEOTHERDATA'

it works fine.....

The first UPDATE statement works fine within SQL PLUS, just doesn't work in the program using executeUpdate().
>UPDATE TABLE SET COLUMN1 = 'NEWDATA' WHERE COLUMN1 = 'DATA'
change the column column1 of all the rows having the column1 equals to DATA to NEWDATA.
After executing this you must have no value of column1 equals to DATA

>UPDATE TABLE SET COLUMN1 = 'NEWDATA' WHERE COLUMN2 = 'SOMEOTHERDATA'
change the column column1 of all the rows having the column2 equals to SOMEOTHERDATA to NEWDATA.
After executing this all the rows having column2 equals SOMEOTHERDATA have column1 equals NEWDATA

This is the significant of the last query you posted. I see each time you post a different query. Please keep attention on what you are writing. A little thing changing in the query changes the operation done!

Bye, Giant.
ASKER CERTIFIED SOLUTION
Avatar of KartikShah
KartikShah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think a split or delete(no refund).