resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.
2016-08-11 19:21
399 查看
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都不查这个字段,那它当然报找不到。
所以改为:
搞定~~~~~~~~~~~
相关文章推荐
- mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】
- 将爬取的网页数据保存到数据库时报错不能提交JPA,Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB6 \xE2...' for column 'content' at row 1
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row dat
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- java.sql.ResultSet接口: 结果集(客户端存表数据的对象)
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row dat
- mongo里面根据对象字段的ID查询 db.Photo.find({'owner.$id':ObjectId('xxxx')}) , 并且使用forEach循环修改查询的数据
- java.sql.SQLException: ORA-00923: FROM keyword not found where expected
- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 4.
- [Exception JavaWeb 1] - javax.el.PropertyNotFoundException: Property 'id' not found on ..........
- Exception in thread "main" java.sql.SQLException: ORA-00923: FROM keyword not found where expected
- java连接sqlserver2008报错 java.sql.SQLException: 对象名 '表名' 无效.
- Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- Caused by: java.sql.SQLException: Field 'id' doesn't have a default value
- java.lang.IllegalArgumentException: column '_id' does not exist问题的解决方案
- Cause: java.sql.SQLException: The user specified as a definer ('root'@'%') does not exist
- java.sql.SQLException: Operation not allowed after ResultSet closed
- java.lang.IllegalArgumentException: column '_id' does not exist
- mySql错误: java.sql.SQLException: Operation not allowed after ResultSet closed