Esempio n. 1
0
 public Movie getMovieByName(String name) {
   Movie movie = null;
   ResultSet rs;
   String mySelect = "select * from " + table + " where title=\"" + name + "\"";
   try {
     if (cargaControlador() > -1) {
       if (open("jdbc:mysql://" + host + ":" + port + "/" + database, user, pass) > -1) {
         if (select(mySelect) > -1) {
           rs = getRs();
           rs.next();
           movie = new Movie();
           movie.id = (Integer) rs.getObject(Movie.COL_ID + 1);
           movie.title = (String) rs.getObject(Movie.COL_TITLE + 1);
           if (rs.getObject(Movie.COL_YEAR + 1) != null)
             movie.year = rs.getObject(Movie.COL_YEAR + 1).toString();
           movie.loc = (String) rs.getObject(Movie.COL_LOC + 1);
           movie.director = (String) rs.getObject(Movie.COL_DIR + 1);
           movie.other = (String) rs.getObject(Movie.COL_OTHER + 1);
         } else {
           Errors.writeError(Errors.DB_SELECT, mySelect + "\n");
         }
         close();
       }
     }
   } catch (Exception ex) {
     Errors.showError(Errors.DB_SELECT);
     Errors.writeError(Errors.DB_SELECT, mySelect + "\n");
   }
   return movie;
 }
Esempio n. 2
0
 // 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");
   }
 }