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都不查这个字段,那它当然报找不到。

所以改为:

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

												

resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.的更多相关文章

  1. hibernate 出现Caused by: java.sql.SQLException: Column 'id' not found.异常

    用hibernate进行映射查询时,出现Caused by: java.sql.SQLException: Column 'id' not found 异常,检查数据库表及映射都有id且已经正确映射, ...

  2. Spring boot启动时报 java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long错误

    Spring boot启动时报 java.sql.SQLException: java.lang.ClassCastException: java.math.BigInteger cannot be ...

  3. ibatis 更改resultmap后 java.sql.SQLException: Column 'del_status' not found.

    当在resultmap中增加字段后,查询语句也必须增加相应字段,否则会报错, java.sql.SQLException: Column 'del_status' not found. 因为查询结果与 ...

  4. java.sql.SQLException:Column count doesn't match value count at row 1

    1.错误描述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因     在插入数据时,插入的字段 ...

  5. java.sql.SQLException:Column count doesn't match value count at row 1

    1.错误描写叙述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因     在插入数据时,插入的 ...

  6. 启动Spring boot报错:nested exception is java.sql.SQLException: Field 'id' doesn't have a default value

    先看具体日志: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with n ...

  7. Caused by: java.sql.SQLException: Field 'id' doesn't have a default value

    1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception ...

  8. java.sql.SQLException:Column Index out of range,0<1

    1.错误描述 java.sql.SQLException:Column Index out of range,0<1 2.错误原因 try { Class.forName("com.m ...

  9. Hibernate报错:Caused by: java.sql.SQLException: Field 'ID' doesn't have a default value

    问题一: 报错如下: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assig ...

随机推荐

  1. 从idea上通过路径去导入项目

    这里我用git来演示导入. 首先确定你要导入项目的路径.(我这里用码云路径图片做演示) 1.选择 2.填写

  2. React-Native运行知乎日报遇到的问题

    研究几天RN(React-Native)后,跟着官方的demo做了一下电影图片显示的那个,但是总感觉官方的demo欠缺点什么,所以找来找去找到了RN版的知乎日报,话说知乎日报什么版的都有,不信你们上网 ...

  3. SQL Server使用游标或临时表遍历数据

    方法一:使用游标(此方法适用所有情况,对标结构没有特殊要求.) declare @ProductName nvarchar() declare pcurr cursor for select Prod ...

  4. 【bzoj1601】[Usaco2008 Oct]灌水(MST)

    题目:http://hzwer.com/1158.html 分析: 解法很巧妙,弄一个超级源,对某个点装水井相当于把这个点连向超级源,边权为这个点的点权,然后跑最小生成树就行了

  5. 禁用Win10显卡更新

    右键This PC-Properties-Advanced system settings-选择Hardware这个tab-Device installation settings选择No

  6. android之视频播放

    视频播放和音频播放一样,都是使用MediaPlayer来播放的,区别就是MediaPlayer播放视频时是直接在Activity中实现的,而音频播放则需要写到服务中去.使用MediaPlayer只支持 ...

  7. 50-ln 简明笔记

    为文件建立链接 ln [options] existing-file [new-link] ln [options] existing-file-list directory ln可以为一个或多个文件 ...

  8. Apache Tomcat相应插件版本

    参考页面: http://tomcat.apache.org/whichversion.html

  9. win7命令行 端口占用 查询进程号 杀进程

    打开CMD窗口 win+R–>cmd 根据端口号查找进程号 netstat -nao|grep 端口号 根据进程号得到进程名 tasklist |findstr 进程号 杀进程 taskkill ...

  10. 转: linux内核版本本地版本号的检查——setlocalversion

    转载:http://blog.csdn.net/adaptiver/article/details/7225980 1.   引子 编译2.6.35.7 kernel版本的时候发现,"2.6 ...