Пример #1
0
  public boolean recordSurveyFeedback(SurveyFeedback surveyFeedback) {
    try {
      DBConnectionFactory myFactory = DBConnectionFactory.getInstance();
      Connection conn = myFactory.getConnection();

      PreparedStatement ps =
          conn.prepareStatement(
              "INSERT INTO "
                  + SurveyFeedback.TABLE_NAME
                  + " "
                  + "("
                  + SurveyFeedback.COLUMN_COMMENT
                  + ", "
                  + SurveyFeedback.COLUMN_PROGRAM_ID
                  + ", "
                  + SurveyFeedback.COLUMN_QUESTION_NO
                  + ", "
                  + SurveyFeedback.COLUMN_VALUE
                  + ") "
                  + "VALUES(?, ?, ?, ?)");
      ps.setString(1, surveyFeedback.getComment());
      ps.setInt(2, surveyFeedback.getProgramID());
      ps.setInt(3, surveyFeedback.getQuestionNo());
      ps.setInt(4, surveyFeedback.getValue());

      ps.executeUpdate();
      ps.close();
      conn.close();
    } catch (SQLException x) {
      Logger.getLogger(SurveyFeedbackDAO.class.getName()).log(Level.SEVERE, null, x);
      return false;
    }
    return true;
  }
Пример #2
0
  public ArrayList<SurveyFeedback> getListOfSurveyFeedbacks() {
    ArrayList<SurveyFeedback> surveyFeedbacks = new ArrayList<>();
    try {
      DBConnectionFactory myFactory = DBConnectionFactory.getInstance();
      Connection conn = myFactory.getConnection();

      PreparedStatement ps = conn.prepareStatement("SELECT * FROM " + SurveyFeedback.TABLE_NAME);

      ResultSet rs = ps.executeQuery();
      surveyFeedbacks = getDataFromResultSet(rs);

      rs.close();
      ps.close();
      conn.close();
    } catch (SQLException x) {
      Logger.getLogger(SurveyFeedbackDAO.class.getName()).log(Level.SEVERE, null, x);
    }
    return surveyFeedbacks;
  }
Пример #3
0
  public boolean updatePlantingProblem(Plot plot) {
    try {
      DBConnectionFactory myFactory = DBConnectionFactory.getInstance();
      Connection conn = myFactory.getConnection();

      PreparedStatement ps =
          conn.prepareStatement(
              "UPDATE "
                  + Plot.TABLE_NAME
                  + " SET "
                  + Plot.COLUMN_FARM_ID
                  + " = ?, "
                  + Plot.COLUMN_PLOT_ID
                  + " = ?, "
                  + Plot.COLUMN_PLOT_NUMBER
                  + " = ?, "
                  + Plot.COLUMN_PLOT_PLANTED
                  + " = ?, "
                  + Plot.COLUMN_PLOT_SIZE
                  + " = ? "
                  + "WHERE "
                  + Plot.COLUMN_PLOT_ID
                  + " = ?");
      ps.setInt(1, plot.getFarmID());
      ps.setInt(2, plot.getPlotID());
      ps.setInt(3, plot.getPlotNumber());
      ps.setInt(4, plot.getPlotPlanted());
      ps.setDouble(5, plot.getPlotSize());
      ps.setInt(6, plot.getPlotID());

      ps.executeUpdate();
      ps.close();
      conn.close();
    } catch (SQLException ex) {
      Logger.getLogger(PlotDAO.class.getName()).log(Level.SEVERE, null, ex);
      return false;
    }
    return true;
  }
Пример #4
0
  public ArrayList<Plot> getListOfPlotsFromFarm(int farmID) {
    ArrayList<Plot> plots = new ArrayList<>();
    try {
      DBConnectionFactory myFactory = DBConnectionFactory.getInstance();
      Connection conn = myFactory.getConnection();

      PreparedStatement ps =
          conn.prepareStatement(
              "SELECT * FROM " + Plot.TABLE_NAME + " WHERE " + Plot.COLUMN_FARM_ID + " = ?");
      ps.setInt(1, farmID);

      ResultSet rs = ps.executeQuery();
      plots = getDataFromResultSet(rs);

      rs.close();
      ps.close();
      conn.close();
    } catch (SQLException x) {
      Logger.getLogger(PlotDAO.class.getName()).log(Level.SEVERE, null, x);
    }
    return plots;
  }
Пример #5
0
  public boolean createPlot(Plot plot) {
    try {
      DBConnectionFactory myFactory = DBConnectionFactory.getInstance();
      Connection conn = myFactory.getConnection();

      PreparedStatement ps =
          conn.prepareStatement(
              "INSERT INTO "
                  + Plot.TABLE_NAME
                  + " "
                  + "("
                  + Plot.COLUMN_FARM_ID
                  + ", "
                  + Plot.COLUMN_PLOT_NUMBER
                  + ", "
                  + Plot.COLUMN_PLOT_ID
                  + ", "
                  + Plot.COLUMN_PLOT_PLANTED
                  + ", "
                  + Plot.COLUMN_PLOT_SIZE
                  + ") "
                  + "VALUES(?, ?, ?, ?, ?)");
      ps.setInt(1, plot.getFarmID());
      ps.setInt(2, plot.getPlotNumber());
      ps.setInt(3, plot.getPlotID());
      ps.setInt(4, plot.getPlotPlanted());
      ps.setDouble(5, plot.getPlotSize());

      ps.executeUpdate();
      ps.close();
      conn.close();
    } catch (SQLException x) {
      Logger.getLogger(PlotDAO.class.getName()).log(Level.SEVERE, null, x);
      return false;
    }
    return true;
  }