Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date)
- VALUES('The Office', 'A mockumentary on a group of typical office workers, where the workday consists of ego clashes, inappropriate behavior, and tedium. Based on the hit BBC series.', 'http://ia.media-imdb.com/images/M/MV5BMTgzNjAzMDE0NF5BMl5BanBnXkFtZTcwNTEyMzM3OA@@._V1._SY317_CR9,0,214,317_.jpg', '8.9', 'http://www.imdb.com/title/tt0386676/', 'tt0386676', '2005-06-11')
- public boolean insert_tvShow(TvShow tvShow) {
- boolean success = false;
- String plot = tvShow.getPlot();
- plot = plot.replaceAll("'", "''");
- try {
- this.statement = this.connection.createStatement();
- String sqlQuery = String.format("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
- "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
- tvShow.getTitle(),
- plot,
- tvShow.getPoster(),
- tvShow.getImdb_Rating(),
- tvShow.getImdb_url(),
- tvShow.getImdb_id(),
- tvShow.getReleaseDate());
- System.out.println(sqlQuery);
- this.statement.executeUpdate(sqlQuery);
- success = true;
- } catch(Exception e) {
- } finally {
- try {
- connection.close();
- } catch (SQLException e) {}
- }
- return success;
- }
- public boolean insert_tvShow(TvShow tvShow) {
- boolean success = false;
- java.util.Date myDate = new java.util.Date("10/10/2009");
- try {
- String sqlString = "INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
- "VALUES(?, ?, ?, ?, ?, ?, ?)";
- PreparedStatement ps = connection.prepareStatement(sqlString);
- ps.setString(1, tvShow.getTitle());
- ps.setString(2, tvShow.getPlot());
- ps.setString(3, tvShow.getPoster());
- ps.setDouble(4, tvShow.getImdb_Rating());
- ps.setString(5, tvShow.getImdb_url());
- ps.setString(6, tvShow.getImdb_id());
- ps.setDate(7, new java.sql.Date(myDate.getTime()));
- ps.executeUpdate();
- connection.commit();
- success = true;
- } catch(Exception e) {
- //TODO logging
- } finally {
- try {
- connection.close();
- } catch (SQLException e) {}
- }
- return success;
- }
- PreparedStatement ps = this.connection.prepareStatement("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) VALUES(?,?,?,?,?,?,?)");
- ps.setString(1, tvShow.getTitle());
- ps.setString(2, tvSHow.getPlot();
- //etc...
- ps.executeUpdate();
- String sqlQuery = String.format("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
- "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
- tvShow.getTitle(),
- plot,
- tvShow.getPoster(),
- tvShow.getImdb_Rating(),
- tvShow.getImdb_url(),
- tvShow.getImdb_id(),
- tvShow.getReleaseDate());
- PreparedStatement statement = conn.prepareStatement("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
- "VALUES(?,?,?,?,?,?,?)";
- statement.setString(1,"title");
- //rest of setters here
- statement.execute();
- conn.commit();
Add Comment
Please, Sign In to add comment