Code example for PreparedStatement

Methods: setLong, setObject, setString

0
        getJdbcTemplate().update(new PreparedStatementCreator() { 
                public PreparedStatement createPreparedStatement(
                    Connection connection) throws SQLException {
                    String sql = "insert into T_COMMENT(BLOG_ID, COMMENT_CONTENT, COMMENT_USER_NAME, COMMENT_USER_EMAIL, COMMENT_DATE) values(?,?,?,?,?)";
                    PreparedStatement stmt = connection.prepareStatement(sql);
                    stmt.setLong(1, comment.getBlog().getBlogID());
                    stmt.setString(2, comment.getCommentContent());
                    stmt.setString(3, comment.getCommentUserName());
                    stmt.setString(4, comment.getCommentUserEmail());
                    stmt.setObject(5, comment.getCommentDate());
 
                    return stmt;
                } 
            }, key);
        comment.setCommentID(key.getKey().longValue());
 
        return comment;
    } 
 
    public Comment getComment(long commentId) {
        String sql = "select * from T_COMMENT where COMMENT_ID = ?";