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都不查這個字段,那它當然報找不到。

所以改為:

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

 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM