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

executeBatch  RSS feed

 
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone done batch sql statements?
I have a bunch of insert statements that will make up an order. I want all the statements to run as one unit, just like a batch, and if any of them fails, it rollsback.
So I was wondering that if setAutoCommit(false) is called on a connection, then run executeBatch on the statement object, which will ahve all the insert statements there. Then check to see if all executed, and if not rollback, otherwise commit.
Is this the way to go, or is there a better way that anyone knows of?
Thanks
Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well looking at Sun press's JDBC book. I found that batch is the way I want to go, I can get transactions in it, and it returns an array of ints if it is completely successful, and throws a BatchUpdateException if any one of the statements fail.
thanks
Mark
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using Oracle, then you can control the number of rows when to do a commit.
You can either do it at the connection level:
((OracleConnection) conn).setDefaultExecuteBatch(n);
or at the PreparedStatement level:
((OraclePreparedStatement) pstmt).setExecuteBatch(n)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!