Beispiel #1
0
  public void true_insert() throws Exception {
    // synchronized(variavel) {

    Database db = new Database();
    db.connect();
    // BEGIN WORK -> stored procedure
    db.update(
        "insert into tbNews (tmsp, headline, body, email) values ('"
            + this.tmsp
            + "', '"
            + this.headline
            + "', '"
            + this.body
            + "', '"
            + this.email
            + "')");
    ResultSet rs = db.query("select max(id) as id from tbNews");
    if (rs.next()) {
      this.id = rs.getInt("id");
    }
    // COMMIT

    db.close();

    // }
  }
Beispiel #2
0
 public News(int id) throws Exception {
   Database db = new Database();
   db.connect();
   News news = News.findById(db, id);
   db.close();
   this.id = news.id;
   this.tmsp = news.tmsp;
   this.headline = news.headline;
   this.body = news.body;
   this.email = news.email;
 }
Beispiel #3
0
 public void update() throws Exception {
   Database db = new Database();
   db.connect();
   db.update(
       "update tbNews set tmsp = '"
           + this.tmsp
           + "', headline = '"
           + this.headline
           + "', body = '"
           + this.body
           + "', email = '"
           + this.email
           + "' where id = "
           + this.id);
   db.close();
 }
Beispiel #4
0
 public static ResultSet findLast(Database db, int n) throws Exception {
   return db.query(
       "select id, tmsp, headline, body, email from tbNews order by tmsp desc limit " + n);
 }
Beispiel #5
0
 public static ResultSet findByEmail(Database db, String email) throws Exception {
   return db.query(
       "select id, tmsp, headline, body, email from tbNews where email = '" + email + "'");
 }
Beispiel #6
0
 public static News findById(Database db, int id) throws Exception {
   return News.next(
       db.query("select id, tmsp, headline, body, email from tbNews where id = " + id));
 }
Beispiel #7
0
 // finders
 public static ResultSet findAll(Database db) throws Exception {
   return db.query("select id, tmsp, headline, body, email from tbNews");
 }
Beispiel #8
0
 public void remove() throws Exception {
   Database db = new Database();
   db.connect();
   db.update("delete from tbNews where id = " + this.id);
   db.close();
 }