コード例 #1
0
ファイル: LoginAccess.java プロジェクト: ssatta3/sankar
  public List<Bids> getBidDetails(int empId) {

    Connection con = DBConnectivity.connectDB();
    List<Bids> itemsList = new ArrayList<Bids>();
    Statement ps = null;
    try {
      ps = con.createStatement();
      String bidData =
          "select f.points_added,p.IMG, p.id,p.item_name,p.description from employee_fact f join product_details p"
              + " on f.product_id = p.id where f.employee_id = "
              + empId
              + "";
      ResultSet rs = ps.executeQuery(bidData);
      while (rs.next()) {
        Bids getBids = new Bids();
        getBids.setItemName(rs.getString("item_name"));
        getBids.setDescription(rs.getString("description"));
        getBids.setPoints(rs.getInt("points_added"));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        InputStream in = rs.getBinaryStream("IMG");
        int n = 0;
        try {
          while ((n = in.read(buf)) >= 0) {
            baos.write(buf, 0, n);
          }
          in.close();
        } catch (IOException e) {

          e.printStackTrace();
        }
        getBids.setItemImage(baos.toByteArray());
        getBids.setItemId(rs.getInt("id"));
        itemsList.add(getBids);
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      try {
        con.close();
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return itemsList;
  }
コード例 #2
0
ファイル: LoginAccess.java プロジェクト: ssatta3/sankar
  /**
   * getEmployeeData
   *
   * @param userName
   * @param password
   * @return Employee
   * @throws SQLException
   */
  public Employee getEmployeeData(String userName, String password) throws SQLException {
    Connection con = DBConnectivity.connectDB();
    List<Bids> itemsList = new ArrayList<Bids>();
    Employee empData = new Employee();
    Statement ps;
    String employeeDetailsQuery =
        " select employee_id,employee_name,points_Achived,points_remaining,supervisor_id,total_points"
            + " from employee_details where employee_id in (select employee_id from employee_login where user_name = '"
            + userName
            + "' and password = '******')";

    try {
      ps = con.createStatement();
      ResultSet rs = ps.executeQuery(employeeDetailsQuery);
      while (rs.next()) {
        empData.setEmployeeName(rs.getString("employee_name"));
        empData.setPointsRemaining(rs.getInt("points_remaining"));
        empData.setPointsAchived(rs.getInt("points_Achived"));
        empData.setSupervisorId(rs.getInt("supervisor_id"));
        empData.setTotal_points(rs.getInt("total_points"));
        empData.setEmployeeId(rs.getInt("employee_id"));
      }
      String bidData =
          "select f.points_added,p.IMG, p.id,p.item_name,p.description from employee_fact f join product_details p"
              + " on f.product_id = p.id where f.employee_id in (select employee_id from employee_login where user_name = '"
              + userName
              + "' and password = '******')";
      rs = ps.executeQuery(bidData);
      while (rs.next()) {
        Bids getBids = new Bids();
        getBids.setItemName(rs.getString("item_name"));
        getBids.setDescription(rs.getString("description"));
        getBids.setPoints(rs.getInt("points_added"));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        InputStream in = rs.getBinaryStream("IMG");
        int n = 0;
        try {
          while ((n = in.read(buf)) >= 0) {
            baos.write(buf, 0, n);
          }
          in.close();
        } catch (IOException e) {

          e.printStackTrace();
        }
        getBids.setItemImage(baos.toByteArray());
        getBids.setItemId(rs.getInt("id"));
        itemsList.add(getBids);
      }
      empData.setBids(itemsList);
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      con.close();
    }

    return empData;
  }