*
The moose likes JDBC and the fly likes Not insert in database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Not insert in database" Watch "Not insert in database" New topic
Author

Not insert in database

Arun Bansal
Greenhorn

Joined: Jun 01, 2010
Posts: 11
Hi everyone. i'm a new one to this form.
I'm trying to insert values in emp table in oracle database but when using this code it accept values but not insert that in table. please help me on this. thanks in advance

the code is below





And the run of this program is


D:\My data\MCA\Sem 5\advance java codes\1506jdbccodes>java JdbcTest3
Connection Established.....
Statement created.....
Employee ID : 1
First Name : aa
Last Name : cc

[Added code tags - see UseCodeTags for details]

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Does Record Saved or Record Not Saved appear in output?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

I think you need to call commit() on your Connection object, probably after the if-else block. Alternatively, setAutoCommit(true) after you have created it would suffice instead.

P.S. Never leave Exception handling blocks empty.
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
Arun,
welcome to java ranch.
As james said dont leave the catch block empty.
Keep e.printStackTrace() in your catch block.
And do let us know the error which you are facing.

James,
I think by default it will commit, if you keep connection.setAutocommit(false) explicitly then you need to do connection.commit() in your code.

Regards,
Sriram.V


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Just checked Javadocs, you are right:

...By default a Connection object is in auto-commit mode, which means that it automatically commits changes after executing each statement...
Arun Bansal
Greenhorn

Joined: Jun 01, 2010
Posts: 11
Thanks to all. i got my mistake.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Arun, what was the solution?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not insert in database