my dog learned polymorphism*
The moose likes JDBC and the fly likes insert command is not working. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "insert command is not working." Watch "insert command is not working." New topic
Author

insert command is not working.

K Vidhyakar
Ranch Hand

Joined: Jul 10, 2005
Posts: 68
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

Joined: Aug 12, 2002
Posts: 102
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

Joined: Jul 10, 2005
Posts: 68
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

Joined: Aug 12, 2002
Posts: 102
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

Joined: Jul 10, 2005
Posts: 68
thanks a lot. its working after calling con.commit() method

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

Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insert command is not working.