• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

batch update

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi...

i m using batch update with oracle 10 g database ,oracle Thin driver

batch update is working fine..
but problem is
if there is exception in batch update (i.e. BatchUpdateException) then there is no corresponding update in database.

for example

if suppose i m going to insert 5 records into database and there is exception at 3 rd records ...
so first 2 records should be insert into database. but it does not happen..?
in database there is no entry for any records if there is exception...what is reason for that ....

thanks in advance
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you doing the whole batch process in one transaction?
 
pravin karne
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no,i m not doing batch update in single transaction
i.e. autocommit is set to true.

even if autocommit is set to false i.e. batch update is in single transaction there is same problem

but if i use just Statement object rather than PrepareStatement then there is no problem. entry for all records until there is no exception


so i think issue is with PreparedStatement.....

Reply


Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we see your code?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to use getUpdateCounts() to debug

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/BatchUpdateException.html#getUpdateCounts()
 
pravin karne
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya i tried for that

i used getUpdateCounts() to debug but it return for all update is Statement.EXECUTE_FAILED even last update is failed

i think it should return Statement.EXECUTE_FAILED for only failed updated
and Statement.SUCCESS_NO_INFO for all successful update in single batch

but it did not happen


thanks for reply
 
pravin karne
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
Can we see your code?



sure...
my code is some what like

Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@10.77.222.118:1521:StratosHearTest","sh_user","sh_user");
String query="insert into SH_Call_Logs (CALLERNUMBER,CALLEDNUMBER,ADCODESEXPOSED,DURATION,TIMEOFDAY,DTMF)values (?,?,?,?,to_date(?,'yyyy/mm/dd:hh:mi:ss am'),?)";
perstmtAnalytics=con.prepareStatement(query);

perstmtAnalytics.setInt(1,123445);
perstmtAnalytics.setInt(2,123445);
perstmtAnalytics.setInt(3,2);
perstmtAnalytics.setInt(4,10);
perstmtAnalytics.setString(5,"2007/08/12");
perstmtAnalytics.setInt(6,0);
perstmtAnalytics.addBatch();
perstmtAnalytics.setInt(1,2234456);
perstmtAnalytics.setInt(2,2234456);
perstmtAnalytics.setInt(3,3);
perstmtAnalytics.setInt(4,10);
perstmtAnalytics.setString(5,"2007/08/13");
perstmtAnalytics.setInt(6,0);
perstmtAnalytics.addBatch();
perstmtAnalytics.setInt(1,323447);
perstmtAnalytics.setInt(2,323447);
perstmtAnalytics.setInt(3,4);
perstmtAnalytics.setInt(4,10);
perstmtAnalytics.setString(5,"2007/08d/14"); // i put error condition with date manually
perstmtAnalytics.setInt(6,0);
perstmtAnalytics.addBatch();
int rows[]=perstmtAnalytics.executeBatch();
[ September 10, 2007: Message edited by: pravin karne ]
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Ater that line

nt rows[]=perstmtAnalytics.executeBatch();

query=null;
perstmtAnalytics=null;

Then try and tell me.
 
pravin karne
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it will not insert anything into database

even after that change
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using the to_date() function? Is there any reason why you don;t just bind a Date object?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic