Advertisement
sorenslothe

setComment-metode

Jun 3rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public static void setComment(Comment comment) {
  2.        
  3.         Connection con = null;
  4.         try {
  5.             con = JDBCConnectionFactory.getNewConnection();
  6.             String sql = "INSERT INTO comments (comments_title, comments_body, comments.student_id, comments.post_id, comments_time_stamp)" + " values (?, ?, ?, ?, NOW())";
  7.            
  8.             PreparedStatement prep = con.prepareStatement(sql);
  9.             prep.setString(1, comment.getCommentTitle());
  10.             prep.setString(2, comment.getCommentBody());  
  11.             prep.setLong(3, comment.getStudentId());
  12.             prep.setInt(4, comment.getPostId());
  13.            
  14.             prep.executeUpdate();
  15.  
  16.         }   catch (SQLException e){
  17.                 e.printStackTrace();
  18.         }   finally {
  19.                 JDBCConnectionFactory.closeConnection(con);
  20.         }
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement