This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

After first update in oracle loop ends  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a loop to update a table(Oracle) multiple times, but after the first update it exits the loop. If i print the statement, loop does not end. What am i missing?
 
Sheriff
Posts: 5115
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Could you post the loop and use code tags. Thanks.
 
Arul Narayanan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Arul Narayanan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Master Rancher
Posts: 3626
39
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get any errors?

You are re-using the statement object while looping over a result set that was created in the original statement.

Re-using the statement will kill the result set of the previous statement and should have resulted in an exception.
 
Arul Narayanan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Guys. I solved by using PreparedStatement.

 
Greenhorn
Posts: 26
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using loops on the statement(Query), Its better if you can use batch update for this.
 
Sheriff
Posts: 23692
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even better if you just use a single update statement which applies to all of the affected rows:

 
Knute Snortum
Sheriff
Posts: 5115
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how the OP can set sal = 5000 for the first emp > 50, then 5001 for the second emp > 50, and so on, with the SQL you are suggesting.
 
Paul Clapham
Sheriff
Posts: 23692
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so I missed the "i = i + 1" bit there. Can't imagine why you would want to add sort of random amounts to people's salaries like that, but I've given up being surprised at the homework assignments that people describe here.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!