Solved

Update Oracle from Java

Posted on 2004-09-27
15
218 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
  • 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now