@Override public void run() { try { // Create server socket serverSocket = new ServerSocket(port); System.out.println("Server started on " + serverSocket.getInetAddress() + " on port " + port); while (true) { Socket clientSocket = serverSocket.accept(); SimpleConnection simpleConnection = new SimpleConnection(clientSocket); simpleConnection.start(); } } catch (IOException e) { System.out.println("Server cannot start on port " + port); System.out.println(e.getMessage()); e.printStackTrace(); } }
public static void viewTable(SimpleConnection simpleConn) throws SQLException { final String query = "SELECT COF_NAME, SUP_ID, PRICE, SALES, TOTAL from " + tableName; try (Connection conn = simpleConn.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query)) { while (rs.next()) { String coffeeName = rs.getString("COF_NAME"); int supplierID = rs.getInt("SUP_ID"); float price = rs.getFloat("PRICE"); int sales = rs.getInt("SALES"); int total = rs.getInt("TOTAL"); System.out.println( coffeeName + ", " + supplierID + ", " + price + ", " + sales + ", " + total); } } catch (SQLException e) { System.err.println(e.getMessage()); } }