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(); // } }
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; }
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(); }
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); }
public static ResultSet findByEmail(Database db, String email) throws Exception { return db.query( "select id, tmsp, headline, body, email from tbNews where email = '" + email + "'"); }
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)); }
// finders public static ResultSet findAll(Database db) throws Exception { return db.query("select id, tmsp, headline, body, email from tbNews"); }
public void remove() throws Exception { Database db = new Database(); db.connect(); db.update("delete from tbNews where id = " + this.id); db.close(); }