Skip to content

Commit

Permalink
Database changes
Browse files Browse the repository at this point in the history
Uses pivotal instead of local db, and also connections are closed when finished
  • Loading branch information
Adam Claxton authored and Adam Claxton committed Mar 22, 2017
1 parent 9847360 commit 2b31f6a
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}


Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand All @@ -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();
}

}

0 comments on commit 2b31f6a

Please sign in to comment.