您的位置:首页 > 编程语言 > Java开发

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




所以改为:



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


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐