Uttam Shukla
Uttam Shukla

Reputation: 13

Importing Excel file in Database using java

I am importing the Excel data into my database using java code. Suppose there are more than 200 rows and I want to stop the import.Is it possible to cancel the import in between and rollback all the data which got created in database while importing ?

Upvotes: 0

Views: 429

Answers (1)

Renis1235
Renis1235

Reputation: 4700

Yes it is. You just have to deactivate autoCommit and commit or rollback whenever you are done.

A simple example:


 DriverManager.registerDriver(new com.mysql.jdbc.Driver());
 String url = "jdbc:mysql://localhost/mydatabase/icpc";
 Connection conn = DriverManager.getConnection("url", "username", "pass");

 // Set the auto commit false. This will execute all
 // SQL statements as individual transactions
 con.setAutoCommit(false);

 // Do your thing with the Excel file...

 // In the end you could either rollback or commit like this
 conn.commit();

 // OR

 conn.rollback();

Upvotes: 1

Related Questions