Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

insert command is not working.

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Friends,
after executing the following code, the table is not inserted with the new value. any body help me with this?
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look for the return value from executeUpdate call. Is it really returning 0? If not so, then probably the autocommit on your connection is false. So you may have to call

before closing statement object.

If, executeUpdate call returns 0, then I am not sure why you did not get any exception.
 
K Vidhyakar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int i=stat.executeUpdate();
System.out.println(i);

prints 1.

So wat may be the problem? is my code is perfect?
or else wat are the things i have to consider regarding the data base. ie ms access.
 
Susanta Chatterjee
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very good that executeUpdate returns 1. Now, try putting con.commit() before closing statement object, as I have suggested before. Looks like, connections are not set to autocommit on your database and you do have to do it as part of your program.

You may talk to your DBA (or look for documentation to see how if you are DBA yourself) if database connections are set to have autocommit false by default.
 
K Vidhyakar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot. its working after calling con.commit() method

stat.executeUpdate();
con.commit() ;
stat.close();
con.close();

Thanks a lot
 
BWA HA HA HA HA HA HA! Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic