コード例 #1
0
 @Override
 public boolean insert(Comment comment) {
   String sql = "INSERT INTO TBLCOMMENT VALUES(nextval('seq_comment'), NOW(), ?, ?, ?,0)";
   try (Connection cnn = dataSource.getConnection();
       PreparedStatement ps = cnn.prepareStatement(sql); ) {
     ps.setString(1, comment.getCommentText());
     ps.setInt(2, Integer.parseInt(Encryption.decode(comment.getVideoId())));
     ps.setInt(3, Integer.parseInt(Encryption.decode(comment.getUserId())));
     if (ps.executeUpdate() > 0) {
       return true;
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (NumberFormatException e1) {
     System.out.println(e1.getMessage());
     return false;
   }
   return false;
 }
コード例 #2
0
 @Override
 public int insertReturnId(Comment comment) {
   String sql = "INSERT INTO TBLCOMMENT VALUES(nextval('seq_comment'), NOW(), ?, ?, ?,0)";
   try (Connection cnn = dataSource.getConnection();
       PreparedStatement ps =
           cnn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS); ) {
     ps.setString(1, comment.getCommentText());
     ps.setInt(2, Integer.parseInt(Encryption.decode(comment.getVideoId())));
     ps.setInt(3, Integer.parseInt(Encryption.decode(comment.getUserId())));
     if (ps.executeUpdate() > 0) {
       ResultSet rs = ps.getGeneratedKeys();
       rs.next();
       return rs.getInt(1);
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (NumberFormatException e1) {
     System.out.println(e1.getMessage());
     return 0;
   }
   return 0;
 }
コード例 #3
0
 @Override
 public boolean update(Comment comment) {
   String sql =
       "UPDATE TBLCOMMENT SET commenttext=?, videoid=?, userid=?, replycomid=? WHERE commentid=?";
   try (Connection cnn = dataSource.getConnection();
       PreparedStatement ps = cnn.prepareStatement(sql); ) {
     ps.setString(1, comment.getCommentText());
     ps.setInt(2, Integer.parseInt(Encryption.decode(comment.getVideoId())));
     ps.setInt(3, Integer.parseInt(Encryption.decode(comment.getUserId())));
     ps.setInt(4, Integer.parseInt(Encryption.decode(comment.getReplyId())));
     ps.setInt(5, Integer.parseInt(Encryption.decode(comment.getCommentId())));
     if (ps.executeUpdate() > 0) {
       return true;
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (NumberFormatException e1) {
     System.out.println(e1.getMessage());
     return false;
   }
   return false;
 }