用于内部联接的JDBCTemplate RowMapper

时间:2016-11-18 16:02:26

标签: sql-server spring jdbctemplate

服务器通知错误

  

HTTP状态500 - 请求处理失败;嵌套异常是   org.springframework.dao.TransientDataAccessResourceException:   StatementCallback; SQL [SELECT * FROM Accounts INNER JOIN Comment ON   Comment.Account_ID = Accounts.Account_ID WHERE Comment.Place_ID = 3];该   列名Account.Account_ID无效。嵌套异常是   com.microsoft.sqlserver.jdbc.SQLServerException:列名   Accounts.Account_ID无效。

这是我在DAO中的代码

public List<LoadCommentDTO> loadComment(int placeId) {
        String sql = "SELECT * FROM Accounts INNER JOIN Comment ON Comment.Account_ID=Accounts.Account_ID WHERE Comment.Place_ID="+ placeId ;
        RowMapper<LoadCommentDTO> rowMapper = new CommentRowMapper();
        List<LoadCommentDTO> listComment = jdbcTemplate.query(sql, rowMapper);
        return listComment;
    }

    protected class CommentRowMapper implements RowMapper<LoadCommentDTO> {
        @Override
        public LoadCommentDTO mapRow(ResultSet rs, int rowNum) throws SQLException {
            LoadCommentDTO loadCommentDTO = new LoadCommentDTO();
            CommentDTO commentDTO  = new CommentDTO();
            AccountDTO accountDTO = new AccountDTO();

            accountDTO.setAccountID(rs.getInt("Accounts.Account_ID"));
            accountDTO.setAvatar_path(rs.getString("Accounts.Avatar_path"));
            accountDTO.setFirstname(rs.getString("Accounts.Firstname"));
            accountDTO.setLastname(rs.getString("Accounts.Lastname"));

            commentDTO.setAccount_Id(rs.getInt("Comment.Account_ID"));
            commentDTO.setDescription(rs.getString("CommentDescription"));
            commentDTO.setPlace_ID(rs.getInt("CommentPlace_ID"));
            commentDTO.setC_Date(rs.getString("CommentC_Date"));

            loadCommentDTO.setAccountDTO(accountDTO);
            loadCommentDTO.setCommentDTO(commentDTO);

            return loadCommentDTO;
        }
    }

0 个答案:

没有答案