diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index c15a778..3fffe9a 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -8,9 +8,14 @@ public class MySQLAccess { - String database = "jdbc:mysql://localhost:3306/seniordesign"; - String user = "root"; - String password = "1234"; + // String database = "jdbc:mysql://localhost:3306/seniordesign"; + // String user = "root"; + // String password = "1234"; + String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; + String user = "b372dfe7409692"; + String password = "74f6e317"; + + String[][] result = new String[20][3]; public void connectDB() throws SQLException, ClassNotFoundException { @@ -31,10 +36,14 @@ public void connectDB() throws SQLException, ClassNotFoundException { result[i][2] = hardwareType; } } + statement.close(); + connect.close(); } public String[][] getResult(){ return result; + statement.close(); + connect.close(); } @@ -44,6 +53,8 @@ public void initializeEmployee(int id) throws ClassNotFoundException, SQLExcepti Connection connect = DriverManager.getConnection(database,user,password); Statement statement = connect.createStatement(); statement.executeUpdate("INSERT INTO employee (Employee_ID) VALUES ("+id+");"); + statement.close(); + connect.close(); } public void updateEmployee(int id, String name, String phone, int location) throws ClassNotFoundException, SQLException @@ -60,6 +71,8 @@ public void updateEmployee(int id, String name, String phone, int location) thro query+=" WHERE Employee_ID="+id; System.out.println(query); statement.executeUpdate(query); + statement.close(); + connect.close(); } public User getEmployeeByID(int id) throws ClassNotFoundException, SQLException @@ -79,6 +92,8 @@ public User getEmployeeByID(int id) throws ClassNotFoundException, SQLException resultSet.next(); employee.setLocationName(resultSet.getString("Address")); return employee; + statement.close(); + connect.close(); } public int locationStringToInt(String locString) throws SQLException, ClassNotFoundException @@ -89,6 +104,8 @@ public int locationStringToInt(String locString) throws SQLException, ClassNotFo ResultSet resultSet = statement.executeQuery("SELECT Location_ID FROM location WHERE Address = '"+locString+"'"); resultSet.next(); return resultSet.getInt("Location_ID"); + statement.close(); + connect.close(); } public String locationIntToString(int locInt) throws ClassNotFoundException, SQLException @@ -99,6 +116,8 @@ public String locationIntToString(int locInt) throws ClassNotFoundException, SQL ResultSet resultSet = statement.executeQuery("SELECT Address FROM location WHERE Location_ID = "+locInt); resultSet.next(); return resultSet.getString("Address"); + statement.close(); + connect.close(); } // returns ID of new location @@ -114,6 +133,8 @@ public int addLocation(String state, String address, String town, int zip) throw +" VALUES ("+id+", "+name+", "+address+", "+town+", "+state+", "+zip+");"; statement.executeUpdate(query); return id; + statement.close(); + connect.close(); } public Location[] getLocations() throws SQLException, ClassNotFoundException @@ -141,6 +162,8 @@ public Location[] getLocations() throws SQLException, ClassNotFoundException i++; } return locations; + statement.close(); + connect.close(); } public void generateTicket(int requester, int location, int device) throws ClassNotFoundException, SQLException { @@ -162,6 +185,8 @@ public void generateTicket(int requester, int location, int device) throws Class query+= "'"+time+"'" +");"; System.out.println(query); statement.executeUpdate(query); + statement.close(); + connect.close(); } }