diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp
index d2cb072..b41f1f9 100644
--- a/WebContent/html/javascript/listing.jsp
+++ b/WebContent/html/javascript/listing.jsp
@@ -1,178 +1,4 @@
-<<<<<<< HEAD
-<%@ page import = "database.MySQLAccess" %>
-<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
-
-
-
-
-Insert title here
-
-
-<%
-/*MySQLAccess myaccess = new MySQLAccess();
-myaccess.connectDB();
-String name = myaccess.getResult()[0][0];
-String description = myaccess.getResult()[0][1];
-String hardware = myaccess.getResult()[0][2];*/
-//out.println(name);
-//out.println(description);
-//out.println(hardware);
-%>
-
-
-
-=======
-<%@ page import = "database.MySQLAccess" %>
+<%@ page import = "database.MySQLAccess,entities.ListedDevice" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
@@ -184,32 +10,29 @@ function isUnavailable(id){
<%
MySQLAccess myaccess = new MySQLAccess();
-myaccess.connectDB();
-String name = myaccess.getResult()[0][0];
-String description = myaccess.getResult()[0][1];
-String hardware = myaccess.getResult()[0][2];
-System.out.println(name);
+ListedDevice[] mydevices = myaccess.getAllDevices();
+
+//string representation of array.
+String deviceString = ListedDevice.arrayToString(mydevices);
//out.println(description);
//out.println(hardware);
+
%>
->>>>>>> refs/remotes/origin/master
\ No newline at end of file
diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java
index 0c6bf04..404d095 100644
--- a/src/database/MySQLAccess.java
+++ b/src/database/MySQLAccess.java
@@ -1,60 +1,86 @@
-package database;
-
-import java.sql.*;
-
-import entities.RentedDevice;
-
-public class MySQLAccess {
-
- String[][] result = new String[20][3];
-
- public void connectDB() throws SQLException, ClassNotFoundException {
- System.getenv("VCAP_SERVICES");
- Class.forName("com.mysql.jdbc.Driver");
- Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
- Statement statement = connect.createStatement();
- //PreparedStatement preparedStatement = null;
- ResultSet resultSet = statement.executeQuery("SELECT * FROM devices");
-
- while(resultSet.next()){
- String deviceName = resultSet.getString("Device_Name");
- String deviceDescription = resultSet.getString("Device_Description");
- String hardwareType = resultSet.getString("Hardware_Model");
-
- for(int i = 0; i<1; i++){
- result[i][0] = deviceName;
- result[i][1] = deviceDescription;
- result[i][2] = hardwareType;
- }
- }
- }
-
- public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNotFoundException{
- //Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter
- System.getenv("VCAP_SERVICES");
- Class.forName("com.mysql.jdbc.Driver");
- Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
- Statement stmt = connect.createStatement();
- ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID);
- int counter = 0;
-
- resultSet.last();
- int rows = resultSet.getRow();
- resultSet.beforeFirst();
-
- //Covers amount of rows, and 6 attributes (indices 0-5)
- RentedDevice[] devices = new RentedDevice[rows];
-
- //iterate result set
- while(resultSet.next()){
- devices[counter] = new RentedDevice(resultSet.getInt("Device_ID") + "",resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getInt("Ticket_ID") + "",resultSet.getString("Hardware"),resultSet.getString("Model"),resultSet.getString("Borrow_Date"));
- counter++;
- }
-
- return devices;
- }
-
- public String[][] getResult(){
- return result;
- }
-}
+package database;
+
+import java.sql.*;
+
+import entities.ListedDevice;
+import entities.RentedDevice;
+
+public class MySQLAccess {
+
+ String[][] result = new String[20][3];
+
+ public void connectDB() throws SQLException, ClassNotFoundException {
+ System.getenv("VCAP_SERVICES");
+ Class.forName("com.mysql.jdbc.Driver");
+ Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
+ Statement statement = connect.createStatement();
+ //PreparedStatement preparedStatement = null;
+ ResultSet resultSet = statement.executeQuery("SELECT * FROM devices");
+
+ while(resultSet.next()){
+ String deviceName = resultSet.getString("Device_Name");
+ String deviceDescription = resultSet.getString("Device_Description");
+ String hardwareType = resultSet.getString("Hardware_Model");
+
+ for(int i = 0; i<1; i++){
+ result[i][0] = deviceName;
+ result[i][1] = deviceDescription;
+ result[i][2] = hardwareType;
+ }
+ }
+ }
+
+ public RentedDevice[] getUserDevices(String userID) throws SQLException, ClassNotFoundException{
+ //Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter
+ System.getenv("VCAP_SERVICES");
+ Class.forName("com.mysql.jdbc.Driver");
+ Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
+ Statement stmt = connect.createStatement();
+ ResultSet resultSet = stmt.executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Hardware, Model, Borrow_Date FROM devices WHERE Renter = " + userID);
+ int counter = 0;
+
+ resultSet.last();
+ int rows = resultSet.getRow();
+ resultSet.beforeFirst();
+
+ //Covers amount of rows, and 6 attributes (indices 0-5)
+ RentedDevice[] devices = new RentedDevice[rows];
+
+ //iterate result set
+ while(resultSet.next()){
+ devices[counter] = new RentedDevice(resultSet.getInt("Device_ID") + "",resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getInt("Ticket_ID") + "",resultSet.getString("Hardware"),resultSet.getString("Model"),resultSet.getString("Borrow_Date"));
+ counter++;
+ }
+
+ return devices;
+ }
+
+ public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundException{
+ //Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter
+ System.getenv("VCAP_SERVICES");
+ Class.forName("com.mysql.jdbc.Driver");
+ Connection connect = DriverManager.getConnection("jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317", "b372dfe7409692", "74f6e317");
+ Statement stmt = connect.createStatement();
+ ResultSet resultSet = stmt.executeQuery("SELECT * FROM devices");
+ int counter = 0;
+
+ resultSet.last();
+ int rows = resultSet.getRow();
+ resultSet.beforeFirst();
+
+ //Covers amount of rows, and 6 attributes (indices 0-5)
+ ListedDevice[] devices = new ListedDevice[rows];
+
+ //iterate result set
+ while(resultSet.next()){
+ devices[counter] = new ListedDevice(resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"),resultSet.getString("Model"));
+ counter++;
+ }
+
+ return devices;
+ }
+
+ public String[][] getResult(){
+ return result;
+ }
+}
diff --git a/src/entities/ListedDevice.java b/src/entities/ListedDevice.java
new file mode 100644
index 0000000..77877dc
--- /dev/null
+++ b/src/entities/ListedDevice.java
@@ -0,0 +1,50 @@
+package entities;
+/**
+ * Simple Modification of the RentedDevice class for use in the listed devices page.
+ * @author John Costa III
+ *
+ */
+public class ListedDevice {
+ private String Device_Name;
+ private String Device_Description;
+ private String Hardware;
+ private String Model;
+ public ListedDevice(String name, String desc, String hardware, String model) {
+ Device_Name = name;
+ Device_Description = desc;
+ Hardware = hardware;
+ Model = model;
+ }
+ /**
+ * Formatting the device to fit a JSON object.
+ * @author - Connor
+ */
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ String comma = ", ";
+ sb.append("{\"name\": \"").append(Device_Name).append("\"").append(comma);
+ sb.append("\"description\": \"").append(Device_Description).append("\"").append(comma);
+ sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma);
+ sb.append("\"model\": \"").append(Model).append("\"");
+ sb.append("}");
+ return sb.toString();
+ }
+ /**
+ * This is a static function which will turn a Listed Device array into its proper string. (modification)
+ * @author - Connor
+ * @param array
+ * @return
+ */
+ public static String arrayToString(ListedDevice[] array){
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+ for(int i = 0; i < array.length; i++){
+ sb.append(array[i].toString());
+ if(i+1 != array.length){
+ sb.append(",");
+ }
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+}