Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating a record

 
lucky soni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Not able to insert into access database....getiing a msg Row is added and .ldb file is getting created but the database has no new row added.
but able to query the database and get results
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For inserting or manipulating with the database(i.e. for DML commands), you should use PreparedStatement instead of simple Statement.
Statement should be used normally for DDL commands like select, delete and so on.

Example:
PreparedStatement pst= con.prepareStatement(sql);

Also, catch SQLException and close the connection and PreparedStatement in the finally block(*very important*).
You should always close the connection.

Thanks,
Ashwini Kashyap | www.infocepts.com
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic