예제 #1
0
파일: Server.java 프로젝트: xdire/Thing
  @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();
    }
  }
예제 #2
0
  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());
    }
  }