• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insert command is not working.

 
K Vidhyakar
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?
 
Susanta Chatterjee
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic