-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBReset.java
More file actions
40 lines (34 loc) · 1.33 KB
/
DBReset.java
File metadata and controls
40 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package kitordersystem;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.sql.SQLException;
/**
* How the program resets the database if everything goes wrong with it, or
* it gets too cluttered. Most of the heavy lifting is done through Mybatis,
* which is far more powerful than this project needs but it works very well.
*/
public class DBReset {
public DBReset(){
String SQLFilePath = "/Users/tsmoffat/kitordersystem/kitordersystem/" +
"kitordersystem/KitOrderProper.sql";
try{
System.out.println("RESETTING");
Connection conn = new getConnection().getConnection();
ScriptRunner sr = new ScriptRunner(conn);
Reader reader = new BufferedReader(new FileReader(SQLFilePath));
sr.runScript(reader);
} catch (SAXException | SQLException | ParserConfigurationException |
IOException e) {
e.printStackTrace();
} catch (Exception e){
System.err.println("Failed to execute " + SQLFilePath + ". The " +
"error is " + e.getMessage());
}
}
}