zoukankan      html  css  js  c++  java
  • 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都不查这个字段,那它当然报找不到。

    所以改为:

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

    
    
  • 相关阅读:
    ideaj项目切换不同版本的jdk
    物理机(window)安装linux系统
    linux jar自启动
    swap扩容
    tomcat加载外部项目
    springboot2.3.2控制台输出@RequestMapping路径
    linux磁盘扩容
    springboot-easycode配置文件修改
    List
    Map HashMap跟HashTable
  • 原文地址:https://www.cnblogs.com/sincoolvip/p/5762276.html
Copyright © 2011-2022 走看看