Solved

Update Oracle from Java

Posted on 2004-09-27
15
222 Views
Last Modified: 2010-03-31
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!
0
Comment
Question by:jhughes4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
  • +1
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12164797
> stmt.executeQuery(Query);

should be:

stmt.executeUpdate(Query);
0
 

Author Comment

by:jhughes4
ID: 12165079
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
0
 
LVL 92

Expert Comment

by:objects
ID: 12165083
whats the return value from the above call?
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:jhughes4
ID: 12165134
Nothing.  Should I be using a ResultSet to loop through the return?
0
 
LVL 92

Expert Comment

by:objects
ID: 12165162
What do you mean by nothing? It returns a value indicating the number of rows updated.
0
 

Author Comment

by:jhughes4
ID: 12165203
Sorry 2.
0
 
LVL 92

Expert Comment

by:objects
ID: 12165231
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.
0
 

Author Comment

by:jhughes4
ID: 12165509
That's correct, but when I execute a select statement from SQL PLUS, the updates don't show.  The 'oldvalues' are still there.
0
 
LVL 92

Expert Comment

by:objects
ID: 12165524
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'?
0
 

Author Comment

by:jhughes4
ID: 12166134
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().
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12166901
>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.
0
 
LVL 1

Accepted Solution

by:
KartikShah earned 150 total points
ID: 12168358
Looking at the thread, I feel that, the commit is not being executed.

The possiblility is that, autoCommit has been set to false, and at the same time, commit is not being called, and as per the normal procedure, if a connection is closed, all uncommited transactions are rolled back.

What you can try is, after the update,

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

call commit and then try check, i.e.

<Connection Object>.commit();

This will commit the update, and then it should be visible.

Hope it helps. :)

Cheers

Kartik
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12408059
I think a split or delete(no refund).
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12420837
?
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 39
How do I remove an object from a 3 53
java example issue 5 46
passing enum to a method 4 35
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question