• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not insert in database

 
Arun Bansal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does Record Saved or Record Not Saved appear in output?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all. i got my mistake.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun, what was the solution?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic