Advertisement
Guest User

Untitled

a guest
Jun 1st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1.  
  2. <-------------------------Java kode ------------------------------>
  3.  
  4. public static Comment getCommentById(long Comment_id) {
  5.  
  6. Comment result = null;
  7. Connection myConn = null;
  8.  
  9. try {
  10. myConn = JDBCConnectionFactory.getNewConnection();
  11.  
  12. String sql = "SELECT * FROM Comment WHERE comment_id = ?";
  13. PreparedStatement prep = myConn.prepareStatement(sql);
  14. prep.setLong(1, Comment_id);
  15.  
  16. ResultSet res = prep.executeQuery();
  17.  
  18. result = createCommentFromResultSet(res);
  19.  
  20. } catch (SQLException e) {
  21. e.printStackTrace();
  22. } finally {
  23. JDBCConnectionFactory.closeConnection(myConn);
  24.  
  25. }
  26. return result;
  27.  
  28. }
  29.  
  30.  
  31. <------------------- Her kommer vores JSP-Hiphop forum ----------------------------------------->
  32.  
  33.  
  34. <%
  35. JDBCConnectionFactory.initManualConnectionHandling("jdbc:mysql://student.hum.au.dk:3306/u201507985",
  36. "u201507985", "Butm51uR", "com.mysql.jdbc.Driver");
  37. ArrayList<Post> posts = PostDao.getPostsByGenre("Hiphop");
  38. ArrayList<Comment> newComments = CommentDAO.getAllComments();
  39. for (Post post : posts) {
  40.  
  41. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement