resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.

resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.

代码:

String sql="SELECT d.content,c.name AS categoryName FROM news_detail d,news_category c WHERE d.categoryId=c.id";
        Object[] params ={};
        System.out.println(this.executeQuery(sql, params));
        ResultSet resultset = this.executeQuery(sql, params);
        System.out.println("不ok???????????????");
        try {
            while(resultset.next()){
                int id =resultset.getInt("id");
                int categoryId = resultset.getInt("categoryId");
                String categoryName = resultset.getString("categoryName");
                String title = resultset.getString("title");
                String summary =  resultset.getString("summary");
                String content = resultset.getString("content");
                String author = resultset.getString("author");
                Timestamp createDate = resultset.getTimestamp("createDate");
                News news =new News();
                news.setId(id);
                news.setCategoryId(categoryId);
                news.setTitle(title);
                news.setSummary(summary);
                news.setContent(content);
                news.setAuthor(author);
                news.setCategoryName(categoryName);
                news.setCreateDate(createDate);
                
                newslist.add(news);
int id =resultset.getInt("id");的时候报错
原因:与下面查询sql中的查询结果字段要匹配,要有这个结果才行,因为resultset取的是符合sql条件的结果集中每个字段,如果你select都不查这个字段,那它当然报找不到。

所以改为:

搞定~~~~~~~~~~~


posted @ 2016-08-11 19:21  sincoolvip  阅读(9504)  评论(0编辑  收藏  举报