Skip to content

Commit

Permalink
TRUNCATE
Browse files Browse the repository at this point in the history
  • Loading branch information
siqq committed Sep 10, 2014
1 parent 9fda9ff commit 0ea46d6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Java-Missle/src/main/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
import missile.DestructedLanucher;
import missile.DestructedMissile;
import missile.Missile;

import org.xml.sax.SAXException;

import view.WarGui;
import war.War;
import war.WarUtility;
import war.controller.AbstractWarView;
import war.controller.WarController;
import war.db.WarDBConnection;

public class Program {
public static final String LAUNCHER = "launcher";
Expand All @@ -34,7 +37,7 @@ public static void main(String[] args) {

try {
// War warModel = xml.readXML();

WarDBConnection.clearWarDataBase();
War warModel = new War();
AbstractWarView viewGui = new WarGui();

Expand Down
29 changes: 25 additions & 4 deletions Java-Missle/src/war/db/WarDBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
Expand All @@ -26,6 +24,10 @@ public class WarDBConnection {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(dbUrl, "root", "");

// Empty all tables when the program starts


} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
Expand Down Expand Up @@ -74,8 +76,13 @@ public static void updateMissileStatus(String id, String status) {
}
}

public static void addNewLauncher(){
// TO DO
public static void addNewLauncher(String launcherId){
try {
statement = (PreparedStatement) connection.prepareStatement("INSERT INTO war.launchers (id, date) VALUES (?, now(), ?, ?, ?, ?)");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void addNewDestructor(){
Expand All @@ -86,6 +93,20 @@ public static void updateLauncherStatus(){
// TO DO
}

public static void clearWarDataBase(){
try {
statement = (PreparedStatement) connection.prepareStatement("TRUNCATE TABLE `launchers`");
statement.execute();
statement = (PreparedStatement) connection.prepareStatement("TRUNCATE TABLE `missile`");
statement.execute();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

public static List<String> getAllTablesNames() {
List<String> allTables = new ArrayList<String>();
try {
Expand Down

0 comments on commit 0ea46d6

Please sign in to comment.