Guest User

Untitled

a guest
Jul 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date)
  2. 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')
  3.  
  4. public boolean insert_tvShow(TvShow tvShow) {
  5.  
  6. boolean success = false;
  7. String plot = tvShow.getPlot();
  8. plot = plot.replaceAll("'", "''");
  9.  
  10. try {
  11. this.statement = this.connection.createStatement();
  12. String sqlQuery = String.format("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
  13. "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
  14. tvShow.getTitle(),
  15. plot,
  16. tvShow.getPoster(),
  17. tvShow.getImdb_Rating(),
  18. tvShow.getImdb_url(),
  19. tvShow.getImdb_id(),
  20. tvShow.getReleaseDate());
  21. System.out.println(sqlQuery);
  22. this.statement.executeUpdate(sqlQuery);
  23. success = true;
  24. } catch(Exception e) {
  25.  
  26. } finally {
  27. try {
  28. connection.close();
  29. } catch (SQLException e) {}
  30. }
  31.  
  32. return success;
  33. }
  34.  
  35. public boolean insert_tvShow(TvShow tvShow) {
  36.  
  37. boolean success = false;
  38. java.util.Date myDate = new java.util.Date("10/10/2009");
  39.  
  40. try {
  41. String sqlString = "INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
  42. "VALUES(?, ?, ?, ?, ?, ?, ?)";
  43. PreparedStatement ps = connection.prepareStatement(sqlString);
  44. ps.setString(1, tvShow.getTitle());
  45. ps.setString(2, tvShow.getPlot());
  46. ps.setString(3, tvShow.getPoster());
  47. ps.setDouble(4, tvShow.getImdb_Rating());
  48. ps.setString(5, tvShow.getImdb_url());
  49. ps.setString(6, tvShow.getImdb_id());
  50. ps.setDate(7, new java.sql.Date(myDate.getTime()));
  51. ps.executeUpdate();
  52. connection.commit();
  53. success = true;
  54. } catch(Exception e) {
  55. //TODO logging
  56. } finally {
  57. try {
  58. connection.close();
  59. } catch (SQLException e) {}
  60. }
  61. return success;
  62. }
  63.  
  64. PreparedStatement ps = this.connection.prepareStatement("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) VALUES(?,?,?,?,?,?,?)");
  65.  
  66. ps.setString(1, tvShow.getTitle());
  67. ps.setString(2, tvSHow.getPlot();
  68. //etc...
  69.  
  70. ps.executeUpdate();
  71.  
  72. String sqlQuery = String.format("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
  73. "VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
  74. tvShow.getTitle(),
  75. plot,
  76. tvShow.getPoster(),
  77. tvShow.getImdb_Rating(),
  78. tvShow.getImdb_url(),
  79. tvShow.getImdb_id(),
  80. tvShow.getReleaseDate());
  81.  
  82. PreparedStatement statement = conn.prepareStatement("INSERT INTO tvshows (title, plot, poster, imdb_rating, imdb_url, imdb_id, release_date) " +
  83. "VALUES(?,?,?,?,?,?,?)";
  84. statement.setString(1,"title");
  85. //rest of setters here
  86. statement.execute();
  87. conn.commit();
Add Comment
Please, Sign In to add comment