Guest User

Untitled

a guest
Jun 3rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.28 KB | None | 0 0
  1. package dao;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. import javax.sql.DataSource;
  13.  
  14. import action.form.JoinForm;
  15. import action.form.LoginForm;
  16. import action.form.ReviewForm;
  17. import crawl.CrawlBean;
  18. import model.CrawlOutputBean;
  19. import model.ReviewBean;
  20.  
  21. public class MovieDB {
  22. public void DBInput(List<CrawlBean> webinfo) throws Exception {
  23. Connection con = null;
  24.  
  25. PreparedStatement pstmt = null;
  26.  
  27. try {
  28. Class.forName("com.mysql.jdbc.Driver");
  29.  
  30. con = DriverManager.getConnection("jdbc:mysql://localhost/softgshin", "root", "");
  31. con.setAutoCommit(false);
  32. // SQL文を書く
  33. pstmt = con.prepareStatement(
  34. "INSERT INTO movie_info(movie_title, movie_date, movie_genre, movie_duration, director, image_url) "
  35. + "VALUES(?, ?, ?, ?, ?, ?)");
  36. for (CrawlBean cbn : webinfo) {
  37. pstmt.setString(1, cbn.getTitle().replaceAll("~", "@"));
  38. pstmt.setString(2, cbn.getPublished());
  39. pstmt.setString(3, cbn.getGenre());
  40. pstmt.setString(4, cbn.getDuration());
  41. pstmt.setString(5, cbn.getDirector());
  42. pstmt.setString(6,
  43. cbn.getImgurl().substring(cbn.getImgurl().lastIndexOf("/") + 1, cbn.getImgurl().length()));
  44.  
  45. pstmt.executeUpdate();
  46.  
  47. con.commit();
  48. }
  49. } catch (Exception e) {
  50. if (con != null) {
  51. con.rollback();
  52. }
  53. e.printStackTrace();
  54. throw e;
  55.  
  56. } finally {
  57. if (pstmt != null) {
  58. pstmt.close();
  59. }
  60. if (con != null) {
  61. con.close();
  62. }
  63. }
  64.  
  65. }
  66. // public List<CrawlOutputBean> DBrewrite(List<CrawlBean> webinfo) throws Exception {
  67. // List<CrawlOutputBean> koushin = new ArrayList<CrawlOutputBean>();
  68. // Connection con = null;
  69. //
  70. // Statement stmt = null;
  71. // ResultSet rs = null;
  72. //
  73. // try {
  74. // Class.forName("com.mysql.jdbc.Driver");
  75. //
  76. // con = DriverManager.getConnection("jdbc:mysql://localhost/softgshin", "root", "");
  77. //
  78. // stmt = con.createStatement();
  79. //
  80. // String sqlStr = "SELECT movie_id, movie_title, movie_date, movie_genre, movie_duration, director, image_url, likeCount, reviewCount FROM movie_info limit 30";
  81. //
  82. // rs = stmt.executeQuery(sqlStr);
  83. //
  84. // while(rs.next()) {
  85. // for (CrawlBean cbn : webinfo) {
  86. // if(!cbn.getTitle().equals(rs.getString("movie_title").replaceAll("@", "~"))) {
  87. // CrawlOutputBean output = new CrawlOutputBean();
  88. // output.setTitle(cbn.getTitle());
  89. // output.setGenre(cbn.getGenre());
  90. // output.setDirector(cbn.getDirector());
  91. // output.setDuration(cbn.getDuration());
  92. // output.setImgurl(cbn.getImgurl());
  93. // koushin.add(output);
  94. // }
  95. // }
  96. // }
  97. // return koushin;
  98. //
  99. // } catch (Exception e) {
  100. // if (con != null) {
  101. // con.rollback();
  102. // }
  103. // e.printStackTrace();
  104. // throw e;
  105.  
  106. } finally {
  107. if (stmt != null) {
  108. stmt.close();
  109. }
  110. if (con != null) {
  111. con.close();
  112. }
  113. }
  114.  
  115. }
  116. public void updateLike(int likeCount, int movie_id, DataSource source) throws Exception {
  117.  
  118. Connection con = null;
  119. PreparedStatement pstmt = null;
  120.  
  121. try {
  122. con = source.getConnection();
  123. con.setAutoCommit(false);
  124. pstmt = con.prepareStatement(
  125. "UPDATE movie_info SET likeCount = ? WHERE movie_id = ?");
  126.  
  127. pstmt.setInt(1, likeCount);
  128. pstmt.setInt(2, movie_id);
  129.  
  130. pstmt.executeUpdate();
  131.  
  132. con.commit();
  133.  
  134. } catch (Exception e) {
  135. if (con != null) {
  136. con.rollback();
  137. }
  138. e.printStackTrace();
  139. throw e;
  140.  
  141. } finally {
  142. if (pstmt != null) {
  143. pstmt.close();
  144. }
  145. if (con != null) {
  146. con.close();
  147. }
  148. }
  149.  
  150. }
  151. public void updateReviewCount(int reviewCount, int movie_id, DataSource source) throws Exception {
  152.  
  153. Connection con = null;
  154. PreparedStatement pstmt = null;
  155.  
  156. try {
  157. con = source.getConnection();
  158. con.setAutoCommit(false);
  159. pstmt = con.prepareStatement(
  160. "UPDATE movie_info SET reviewCount = ? WHERE movie_id = ?");
  161.  
  162. pstmt.setInt(1, reviewCount);
  163. pstmt.setInt(2, movie_id);
  164.  
  165. pstmt.executeUpdate();
  166.  
  167. con.commit();
  168.  
  169. } catch (Exception e) {
  170. if (con != null) {
  171. con.rollback();
  172. }
  173. e.printStackTrace();
  174. throw e;
  175.  
  176. } finally {
  177. if (pstmt != null) {
  178. pstmt.close();
  179. }
  180. if (con != null) {
  181. con.close();
  182. }
  183. }
  184.  
  185. }
  186.  
  187. public List<CrawlOutputBean> DBoutput(DataSource source) throws Exception {
  188. List<CrawlOutputBean> outputlist = new ArrayList<CrawlOutputBean>();
  189. Connection con = null;
  190. Statement stmt = null;
  191. ResultSet rs = null;
  192.  
  193. try {
  194. con = source.getConnection();
  195.  
  196. stmt = con.createStatement();
  197.  
  198. String sqlStr = "SELECT movie_id, movie_title, movie_date, movie_genre, movie_duration, director, image_url, likeCount, reviewCount FROM movie_info limit 30";
  199.  
  200. rs = stmt.executeQuery(sqlStr);
  201. while (rs.next()) {
  202. CrawlOutputBean li = new CrawlOutputBean();
  203. li.setTitle(rs.getString("movie_title").replaceAll("@", "~"));
  204. li.setPublished(rs.getString("movie_date"));
  205. li.setGenre(rs.getString("movie_genre"));
  206. li.setDuration(rs.getString("movie_duration"));
  207. li.setDirector(rs.getString("director"));
  208. li.setImgurl(rs.getString("image_url"));
  209. li.setMovie_id(Integer.parseInt(rs.getString("movie_id")));
  210. li.setLikeCount(rs.getInt("likeCount"));
  211. li.setReviewCount(rs.getInt("reviewCount"));
  212. outputlist.add(li);
  213. }
  214. } catch (SQLException ex) {
  215. ex.printStackTrace();
  216. throw ex;
  217. } finally {
  218. if (rs != null) {
  219. rs.close();
  220. }
  221. if (con != null) {
  222. con.close();
  223. }
  224. if (stmt != null) {
  225. stmt.close();
  226. }
  227. }
  228. return outputlist;
  229.  
  230. }
  231. public List<CrawlOutputBean> orderbylike(DataSource source) throws Exception {
  232. List<CrawlOutputBean> orderbylike = new ArrayList<CrawlOutputBean>();
  233. Connection con = null;
  234. Statement stmt = null;
  235. ResultSet rs = null;
  236.  
  237. try {
  238. con = source.getConnection();
  239.  
  240. stmt = con.createStatement();
  241.  
  242. String sqlStr = "SELECT movie_id, movie_title, movie_date, movie_genre, movie_duration, director, image_url, likeCount FROM movie_info ORDER BY likeCount DESC";
  243.  
  244. rs = stmt.executeQuery(sqlStr);
  245. while (rs.next()) {
  246. CrawlOutputBean li = new CrawlOutputBean();
  247. li.setTitle(rs.getString("movie_title").replaceAll("@", "~"));
  248. li.setPublished(rs.getString("movie_date"));
  249. li.setGenre(rs.getString("movie_genre"));
  250. li.setDuration(rs.getString("movie_duration"));
  251. li.setDirector(rs.getString("director"));
  252. li.setImgurl(rs.getString("image_url"));
  253. li.setMovie_id(Integer.parseInt(rs.getString("movie_id")));
  254. li.setLikeCount(rs.getInt("likeCount"));
  255. orderbylike.add(li);
  256. }
  257. } catch (SQLException ex) {
  258. ex.printStackTrace();
  259. throw ex;
  260. } finally {
  261. if (rs != null) {
  262. rs.close();
  263. }
  264. if (con != null) {
  265. con.close();
  266. }
  267. if (stmt != null) {
  268. stmt.close();
  269. }
  270. }
  271. return orderbylike;
  272.  
  273. }
  274.  
  275. public int Id(String title, DataSource source) throws Exception {
  276. int movie_id = 0;
  277. Connection con = null;
  278. Statement stmt = null;
  279. ResultSet rs = null;
  280.  
  281. try {
  282. con = source.getConnection();
  283.  
  284. stmt = con.createStatement();
  285.  
  286. String sqlStr = "SELECT movie_id FROM movie_info WHERE movie_title ='" + title.replaceAll("~", "@") + "'";
  287.  
  288. rs = stmt.executeQuery(sqlStr);
  289. while (rs.next()) {
  290.  
  291. movie_id = Integer.parseInt(rs.getString("movie_id"));
  292. }
  293. } catch (SQLException ex) {
  294. ex.printStackTrace();
  295. throw ex;
  296. } finally {
  297. if (rs != null) {
  298. rs.close();
  299. }
  300. if (con != null) {
  301. con.close();
  302. }
  303. if (stmt != null) {
  304. stmt.close();
  305. }
  306. }
  307. return movie_id;
  308.  
  309. }
  310.  
  311. public String userId(int login_id, DataSource source) throws Exception {
  312. String user_id = "";
  313. Connection con = null;
  314. Statement stmt = null;
  315. ResultSet rs = null;
  316. try {
  317. con = source.getConnection();
  318.  
  319. stmt = con.createStatement();
  320.  
  321. String sqlStr = "SELECT user_id FROM login WHERE login_id ='" + login_id + "'";
  322. rs = stmt.executeQuery(sqlStr);
  323. while (rs.next()) {
  324. user_id = rs.getString("user_id");
  325. }
  326. } catch (SQLException ex) {
  327. ex.printStackTrace();
  328. throw ex;
  329. } finally {
  330. if (rs != null) {
  331. rs.close();
  332. }
  333. if (con != null) {
  334. con.close();
  335. }
  336. if (stmt != null) {
  337. stmt.close();
  338. }
  339. }
  340. return user_id;
  341. }
  342.  
  343. public int loginId(String user_id, DataSource source) throws Exception {
  344. int login_id = 0;
  345. Connection con = null;
  346. Statement stmt = null;
  347. ResultSet rs = null;
  348. try {
  349. con = source.getConnection();
  350.  
  351. stmt = con.createStatement();
  352.  
  353. String sqlStr = "SELECT login_id FROM login WHERE user_id ='" + user_id + "'";
  354. rs = stmt.executeQuery(sqlStr);
  355. while (rs.next()) {
  356. login_id = Integer.parseInt(rs.getString("login_id"));
  357. }
  358. } catch (SQLException ex) {
  359. ex.printStackTrace();
  360. throw ex;
  361. } finally {
  362. if (rs != null) {
  363. rs.close();
  364. }
  365. if (con != null) {
  366. con.close();
  367. }
  368. if (stmt != null) {
  369. stmt.close();
  370. }
  371. }
  372. return login_id;
  373.  
  374. }
  375.  
  376. public List<ReviewBean> reviewSearch(int movie_id, DataSource source) throws Exception {
  377. List<ReviewBean> reviewlist = new ArrayList<ReviewBean>();
  378. Connection con = null;
  379. Statement stmt = null;
  380. ResultSet rs = null;
  381.  
  382. try {
  383. con = source.getConnection();
  384.  
  385. stmt = con.createStatement();
  386.  
  387. String sqlStr = "SELECT review_id, login_id, review, inp_date FROM movie_review WHERE movie_id = '" + movie_id + "'";
  388. rs = stmt.executeQuery(sqlStr);
  389.  
  390. while (rs.next()) {
  391. ReviewBean li = new ReviewBean();
  392. li.setReview_id(rs.getInt("review_id"));
  393. li.setLogin_id(Integer.parseInt(rs.getString("login_id")));
  394. li.setReview(rs.getString("review"));
  395. li.setInp_date(rs.getString("inp_date"));
  396. reviewlist.add(li);
  397. }
  398.  
  399. } catch (SQLException ex) {
  400. ex.printStackTrace();
  401. throw ex;
  402. } finally {
  403. if (rs != null) {
  404. rs.close();
  405. }
  406. if (con != null) {
  407. con.close();
  408. }
  409. if (stmt != null) {
  410. stmt.close();
  411. }
  412. }
  413. return reviewlist;
  414.  
  415. }
  416.  
  417. public List<ReviewBean> infoSearch(int movie_id, DataSource source) throws Exception {
  418. List<ReviewBean> infolist = new ArrayList<ReviewBean>();
  419. Connection con = null;
  420. Statement stmt = null;
  421. ResultSet rs = null;
  422. try {
  423. con = source.getConnection();
  424.  
  425. stmt = con.createStatement();
  426.  
  427. String sqlStr = "SELECT movie_title, movie_genre, movie_duration, director, image_url FROM movie_info WHERE movie_id ='"
  428. + movie_id + "' ";
  429. rs = stmt.executeQuery(sqlStr);
  430.  
  431. while (rs.next()) {
  432. ReviewBean cbn = new ReviewBean();
  433. cbn.setMovie_title(rs.getString("movie_title").replaceAll("@", "~"));
  434. cbn.setGenre(rs.getString("movie_genre"));
  435. cbn.setDuration(rs.getString("movie_duration"));
  436. cbn.setDirector(rs.getString("director"));
  437. cbn.setImage_url(rs.getString("image_url"));
  438.  
  439. infolist.add(cbn);
  440. }
  441.  
  442. } catch (SQLException ex) {
  443. ex.printStackTrace();
  444. throw ex;
  445. } finally {
  446. if (rs != null) {
  447. rs.close();
  448. }
  449. if (con != null) {
  450. con.close();
  451. }
  452. if (stmt != null) {
  453. stmt.close();
  454. }
  455. }
  456. return infolist;
  457. }
  458.  
  459.  
  460. public int likeCount(int movie_id, DataSource source) throws Exception {
  461. int like = 0;
  462. Connection con = null;
  463. Statement stmt = null;
  464. ResultSet rs = null;
  465. try {
  466. con = source.getConnection();
  467.  
  468. stmt = con.createStatement();
  469. String sqlStr = "SELECT COUNT(movie_like) FROM movie_review WHERE movie_id ='" + movie_id + "' AND movie_like = '1'";
  470. rs = stmt.executeQuery(sqlStr);
  471. if(rs.next()) {
  472. ReviewBean cbn = new ReviewBean();
  473. cbn.setLike(rs.getInt("COUNT(movie_like)"));
  474. like = rs.getInt("COUNT(movie_like)");
  475. } else {
  476. ReviewBean cbn = new ReviewBean();
  477. cbn.setLike(0);
  478.  
  479. }
  480. } catch (SQLException ex) {
  481. ex.printStackTrace();
  482. throw ex;
  483. } finally {
  484. if (rs != null) {
  485. rs.close();
  486. }
  487. if (con != null) {
  488. con.close();
  489. }
  490. if (stmt != null) {
  491. stmt.close();
  492. }
  493. }
  494. return like;
  495. }
  496. public int reviewCount(int movie_id, DataSource source) throws Exception {
  497. int reviewCount = 0;
  498. Connection con = null;
  499. Statement stmt = null;
  500. ResultSet rs = null;
  501. try {
  502. con = source.getConnection();
  503.  
  504. stmt = con.createStatement();
  505. String sqlStr = "SELECT COUNT(review_id) FROM movie_review WHERE movie_id ='" + movie_id + "'";
  506. rs = stmt.executeQuery(sqlStr);
  507. if(rs.next()) {
  508. ReviewBean cbn = new ReviewBean();
  509. cbn.setReviewCount(rs.getInt("COUNT(review_id)"));
  510. reviewCount = rs.getInt("COUNT(review_id)");
  511. } else {
  512. ReviewBean cbn = new ReviewBean();
  513. cbn.setReviewCount(0);
  514.  
  515. }
  516. } catch (SQLException ex) {
  517. ex.printStackTrace();
  518. throw ex;
  519. } finally {
  520. if (rs != null) {
  521. rs.close();
  522. }
  523. if (con != null) {
  524. con.close();
  525. }
  526. if (stmt != null) {
  527. stmt.close();
  528. }
  529. }
  530. return reviewCount;
  531. }
  532. public void reviewInput(ReviewForm rfm, DataSource source) throws Exception {
  533. Connection con = null;
  534. PreparedStatement pstmt = null;
  535. try {
  536. con = source.getConnection();
  537.  
  538. con.setAutoCommit(false);
  539.  
  540. pstmt = con.prepareStatement(
  541. "INSERT INTO movie_review(movie_id, login_id, movie_like, review, inp_date) "
  542. + "VALUES(?, ?, ?, ?, CURRENT_DATE())");
  543.  
  544. pstmt.setInt(1, rfm.getMovie_id());
  545. pstmt.setInt(2, rfm.getLogin_id());
  546. pstmt.setInt(3, rfm.getLike());
  547. if(rfm.getReview().equals("") && rfm.getLike() == 1) {
  548. pstmt.setString(4, "いいね!");
  549. }else {
  550. pstmt.setString(4, rfm.getReview());
  551. }
  552.  
  553. pstmt.executeUpdate();
  554.  
  555. con.commit();
  556. } catch (Exception e) {
  557. if (con != null) {
  558. con.rollback();
  559. }
  560. e.printStackTrace();
  561. throw e;
  562.  
  563. } finally {
  564. if (pstmt != null) {
  565. pstmt.close();
  566. }
  567. if (con != null) {
  568. con.close();
  569. }
  570. }
  571.  
  572. }
  573.  
  574.  
  575. public List<LoginForm> Search(LoginForm login, DataSource source) throws Exception {
  576. List<LoginForm> list = new ArrayList<LoginForm>();
  577. Connection con = null;
  578. Statement stmt = null;
  579. ResultSet rs = null;
  580.  
  581. try {
  582. con = source.getConnection();
  583.  
  584. stmt = con.createStatement();
  585.  
  586. String sqlStr = "SELECT user_id, passwd FROM login WHERE user_id = '" + login.getId() + "'";
  587.  
  588. rs = stmt.executeQuery(sqlStr);
  589.  
  590. while (rs.next()) {
  591. LoginForm li = new LoginForm();
  592. li.setId(rs.getString("user_id"));
  593. li.setPw(rs.getString("passwd"));
  594.  
  595. list.add(li);
  596. }
  597.  
  598. } catch (SQLException ex) {
  599. ex.printStackTrace();
  600. throw ex;
  601. } finally {
  602. if (rs != null) {
  603. rs.close();
  604. }
  605. if (con != null) {
  606. con.close();
  607. }
  608. if (stmt != null) {
  609. stmt.close();
  610. }
  611. }
  612. return list;
  613. }
  614. public List<JoinForm> JoinSearch(JoinForm jfm, DataSource source) throws Exception {
  615. List<JoinForm> joinlist = new ArrayList<JoinForm>();
  616. Connection con = null;
  617. Statement stmt = null;
  618. ResultSet rs = null;
  619.  
  620. try {
  621. con = source.getConnection();
  622.  
  623. stmt = con.createStatement();
  624.  
  625. String sqlStr = "SELECT user_id, passwd FROM login WHERE user_id = '" + jfm.getId() + "'";
  626.  
  627. rs = stmt.executeQuery(sqlStr);
  628.  
  629. while (rs.next()) {
  630. JoinForm bn = new JoinForm();
  631. bn.setId(rs.getString("user_id"));
  632.  
  633. joinlist.add(bn);
  634. }
  635.  
  636. } catch (SQLException ex) {
  637. ex.printStackTrace();
  638. throw ex;
  639. } finally {
  640. if (rs != null) {
  641. rs.close();
  642. }
  643. if (con != null) {
  644. con.close();
  645. }
  646. if (stmt != null) {
  647. stmt.close();
  648. }
  649. }
  650. return joinlist;
  651. }
  652. public void loginInput(JoinForm jfm, DataSource source) throws Exception {
  653.  
  654. Connection con = null;
  655. PreparedStatement pstmt = null;
  656. ResultSet rs = null;
  657.  
  658. try{
  659. con = source.getConnection();
  660.  
  661. con.setAutoCommit(false);
  662.  
  663. pstmt = con.prepareStatement(
  664. "INSERT INTO login(user_id, passwd, inp_date) "
  665. + "VALUES(?, ?, CURRENT_DATE())");
  666.  
  667. pstmt.setString(1, jfm.getId());
  668. pstmt.setString(2, jfm.getPw());
  669.  
  670. pstmt.executeUpdate();
  671.  
  672. con.commit();
  673.  
  674. } catch (SQLException ex) {
  675. ex.printStackTrace();
  676. throw ex;
  677. } finally {
  678. if (rs != null) {
  679. rs.close();
  680. }
  681. if (con != null) {
  682. con.close();
  683. }
  684. if (pstmt != null) {
  685. pstmt.close();
  686. }
  687. }
  688.  
  689.  
  690. }
  691. public List<ReviewBean> reviewfind(int review_id, DataSource source) throws Exception {
  692. List<ReviewBean> reviewfind = new ArrayList<ReviewBean>();
  693. Connection con = null;
  694. Statement stmt = null;
  695. ResultSet rs = null;
  696.  
  697. try {
  698. con = source.getConnection();
  699.  
  700. stmt = con.createStatement();
  701.  
  702. String sqlStr = "SELECT review_id, login_id, review, inp_date FROM movie_review WHERE review_id = '" + review_id + "'";
  703. rs = stmt.executeQuery(sqlStr);
  704.  
  705. while (rs.next()) {
  706. ReviewBean li = new ReviewBean();
  707. li.setReview_id(rs.getInt("review_id"));
  708. li.setLogin_id(Integer.parseInt(rs.getString("login_id")));
  709. li.setReview(rs.getString("review"));
  710. li.setInp_date(rs.getString("inp_date"));
  711. reviewfind.add(li);
  712. }
  713.  
  714. } catch (SQLException ex) {
  715. ex.printStackTrace();
  716. throw ex;
  717. } finally {
  718. if (rs != null) {
  719. rs.close();
  720. }
  721. if (con != null) {
  722. con.close();
  723. }
  724. if (stmt != null) {
  725. stmt.close();
  726. }
  727. }
  728. return reviewfind;
  729.  
  730. }
  731. public void reviewDelete(int review_id, DataSource source) throws Exception {
  732. Connection con = null;
  733. PreparedStatement pstmt = null;
  734.  
  735. try {
  736. con = source.getConnection();
  737. con.setAutoCommit(false);
  738. pstmt = con.prepareStatement(
  739. "DELETE FROM movie_review WHERE review_id = ?");
  740.  
  741. pstmt.setInt(1, review_id);
  742.  
  743. pstmt.executeUpdate();
  744.  
  745. con.commit();
  746.  
  747. } catch (Exception e) {
  748. if (con != null) {
  749. con.rollback();
  750. }
  751. e.printStackTrace();
  752. throw e;
  753.  
  754. } finally {
  755. if (pstmt != null) {
  756. pstmt.close();
  757. }
  758. if (con != null) {
  759. con.close();
  760. }
  761. }
  762. }
  763. public List<ReviewBean> movieSearch(String search, DataSource source) throws Exception {
  764. List<ReviewBean> searchlist = new ArrayList<ReviewBean>();
  765. Connection con = null;
  766. Statement stmt = null;
  767. ResultSet rs = null;
  768. try {
  769. con = source.getConnection();
  770.  
  771. stmt = con.createStatement();
  772.  
  773. String sqlStr = "SELECT movie_title, movie_genre, movie_duration, director, image_url FROM movie_info";
  774.  
  775. if(!search.equals("")) {
  776. sqlStr += "WHERE movie_title LIKE '%" + search + "%'";
  777. }
  778.  
  779. rs = stmt.executeQuery(sqlStr);
  780.  
  781.  
  782. while (rs.next()) {
  783. ReviewBean cbn = new ReviewBean();
  784. cbn.setMovie_title(rs.getString("movie_title").replaceAll("@", "~"));
  785. cbn.setGenre(rs.getString("movie_genre"));
  786. cbn.setDuration(rs.getString("movie_duration"));
  787. cbn.setDirector(rs.getString("director"));
  788. cbn.setImage_url(rs.getString("image_url"));
  789.  
  790. searchlist.add(cbn);
  791. }
  792.  
  793. } catch (SQLException ex) {
  794. ex.printStackTrace();
  795. throw ex;
  796. } finally {
  797. if (rs != null) {
  798. rs.close();
  799. }
  800. if (con != null) {
  801. con.close();
  802. }
  803. if (stmt != null) {
  804. stmt.close();
  805. }
  806. }
  807. return searchlist;
  808. }
  809.  
  810.  
  811. }
Add Comment
Please, Sign In to add comment