| 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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
|
Does Record Saved or Record Not Saved appear in output?
|
 |
James Boswell
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
|
Arun, what was the solution?
|
 |
 |
|
|
subject: Not insert in database
|
|
|