// DELETE MOVIE FROM DATABASE AND TABLEMODEL public void deleteMovie(int row) { int id = (Integer) tabModel.getValueAt(row, Movie.COL_ID); String myDel = ""; try { if (cargaControlador() > -1) { if (open("jdbc:mysql://" + host + ":" + port + "/" + database, user, pass) > -1) { myDel = "delete from movies where id=\"" + id + "\""; if (delete(myDel) > -1) { // System.out.println("Deleting succesful!!!"); tabModel.deleteMovie(row); } else { Errors.showError(Errors.DB_DELETE); Errors.writeError(Errors.DB_DELETE, myDel + "\n"); } close(); } } } catch (Exception ex) { Errors.showError(Errors.DB_DELETE); Errors.writeError(Errors.DB_DELETE, myDel + "\n"); } }
// UPDATE DISC FROM DATABASE AND TABLEMODEL public void updateMovie(Movie movie, int selectedRow) { String myUpd = ""; try { if (cargaControlador() > -1) { if (open("jdbc:mysql://" + host + ":" + port + "/" + database, user, pass) > -1) { movie.check(); myUpd = "update " + table + " set title=\"" + movie.title + "\",year=\"" + movie.year + "\",loc=\"" + movie.loc + "\",director=\"" + movie.director + "\",other=\"" + movie.other + "\" where id=\"" + movie.id + "\""; // System.out.println(movie.title); if (update(myUpd) > -1) { tabModel.setMovieAtRow(movie, selectedRow); } else { reviewView.append("Error updating fields\n"); } close(); } } } catch (Exception ex) { Errors.showError(Errors.DB_UPDATE); Errors.writeError(Errors.DB_UPDATE, myUpd + "\n"); } }
// INSERT MOVIE IN DATABASE AND TABLEMODEL public void insertNewMovie(Movie movie) { String myInsert = "insert into " + table + " (title,director,year,other,loc) values (\"" + movie.title + "\",\"" + movie.director + "\",\"" + movie.year + "\",\"" + movie.other + "\",\"" + movie.loc + "\")"; try { if (cargaControlador() > -1) { if (open("jdbc:mysql://" + host + ":" + port + "/" + database, user, pass) > -1) { // System.out.println(myInsert); movie.check(); if ((insert(myInsert)) > -1) { movie.id = lastInsertID(); tabModel.addMovie(movie); } else { Errors.showError(Errors.DB_INSERT); Errors.writeError(Errors.DB_INSERT, myInsert + "\n"); } close(); } } } catch (Exception ex) { ex.printStackTrace(); Errors.showError(Errors.DB_INSERT); Errors.writeError(Errors.DB_INSERT, myInsert + "\n"); } }