コード例 #1
0
ファイル: DBNotice.java プロジェクト: MikeBrOl/GatheringApp
  public int deleteNotice(Notice notice) {
    int check = 0;
    Connection con = dbConnection.CONN();

    try {
      String name = notice.getName();

      PreparedStatement stmt = con.prepareStatement("DELETE FROM Notices WHERE Name= ?");

      stmt.setString(1, name);
      check = stmt.executeUpdate();

      stmt.close();
      con.close();
    } catch (Exception e) {
      Log.e("Error", e.getMessage());
      if (con != null) {
        try {
          System.err.print("Transaction is being rolled back");
          con.rollback();
        } catch (SQLException se) {
          Log.e("ERROR", se.getMessage());
        }
      }
    }

    return check;
  }
コード例 #2
0
ファイル: DBNotice.java プロジェクト: MikeBrOl/GatheringApp
  public int insertNotice(Notice notice) {

    Connection con = dbConnection.CONN();
    int check = 0;

    try {
      String name = notice.getName();
      String description = notice.getDescription();
      String address = notice.getAddress();
      float lat = notice.getLatitude();
      float lon = notice.getLongitude();

      String date = notice.getTime();

      PreparedStatement stmt = con.prepareStatement("INSERT INTO Notices VALUES(?, ?, ?, ?, ?, ?)");
      stmt.setString(1, name);
      stmt.setString(2, description);
      stmt.setString(3, address);
      stmt.setString(4, date);
      stmt.setFloat(5, lat);
      stmt.setFloat(6, lon);

      check = stmt.executeUpdate();

      stmt.close();
      con.close();
    } catch (Exception e) {
      Log.e("ERROR", e.getMessage());
    }

    return check;
  }
コード例 #3
0
ファイル: DBNotice.java プロジェクト: MikeBrOl/GatheringApp
  public Notice getNoticeByName(String name) {
    Notice notice = new Notice();

    try {
      Connection con = dbConnection.CONN();

      PreparedStatement stmt = con.prepareStatement("SELECT * FROM Notices WHERE Name = ?");
      stmt.setString(1, name);
      ResultSet rs = stmt.executeQuery();
      rs.next();
      notice.setName(rs.getString("Name"));
      notice.setDescription(rs.getString("Description"));
      notice.setAddress(rs.getString("Address"));
      notice.setTime(rs.getString("Time"));

      rs.close();
      stmt.close();
      con.close();
    } catch (Exception e) {
      Log.e("ERROR", e.getMessage());
    }

    return notice;
  }