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

所以改为:

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


resultset 对象获取行字段数据时报:java.sql.SQLException: Column 'id' not found.

时间: 2024-12-15 01:34:05

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

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

用hibernate进行映射查询时,出现Caused by: java.sql.SQLException: Column 'id' not found 异常,检查数据库表及映射都有id且已经正确映射,google后发现原因为: Your query doesn't return a field named id即查询sql中没有查询出主键id列,但返回结果集中用到,故出现异常特此记录. 详细解答见下: http://stackoverflow.com/questions/34164411/cau

java.sql.SQLException: Field 'id' doesn't have a default value(用eclipse操作数据库时报了这种奇怪的错误)的原因与解决方法

1.错误原因 由于id在数据库表中是作为主键,但是在插入的过程中,没有给予数值,并且没有让其自增 2.解决办法 修改数据库表中的id,让其自增(在插入的过程中,不插入id数据时) java.sql.SQLException: Field 'id' doesn't have a default value(用eclipse操作数据库时报了这种奇怪的错误)的原因与解决方法 原文地址:https://www.cnblogs.com/zyt-bg/p/8385972.html

java.sql.SQLException: Column 'class' not found.异常没有找到列

1 /**处理当个对象的 ,rs中要么有一条,要么一条没有. 2 * @param <T> 3 */ 4 public class BeanHandler<T> implements ResultSetHandler<T> { 5 private Class<T> type; 6 public BeanHandler(Class<T> type){ 7 this.type = type; 8 } 9 /**将rs->T t 10 */ 11

java.sql.SQLException:Column count doesn&#39;t match value count at row 1

1.错误描述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因     在插入数据时,插入的字段个数跟数据库表字段个数不一致 insert into student(sno,sname,sage,ssex) values(1,'张三丰','man'); 3.解决办法     保证插入数据字段个数跟数据库表中的字段个数一致 insert into student(sno,sname,sage,s

java.sql.SQLException:Column count doesn&amp;#39;t match value count at row 1

1.错误描写叙述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因     在插入数据时,插入的字段个数跟数据库表字段个数不一致 insert into student(sno,sname,sage,ssex) values(1,'张三丰','man'); 3.解决的方法     保证插入数据字段个数跟数据库表中的字段个数一致 insert into student(sno,sname,sag

ibatis 更改resultmap后 java.sql.SQLException: Column &#39;del_status&#39; not found.

当在resultmap中增加字段后,查询语句也必须增加相应字段,否则会报错, java.sql.SQLException: Column 'del_status' not found. 因为查询结果与resultmap对应不上,ibatis在查询获得结果集中找不到resultmap的对应字段, 我是在resultmap中增加字段,但select语句中并没有增加,折腾了半天 如果属性类型为基本类型而非包装类型,并且数据库中数据为null,那么就会报错 Caused by: java.lang.Ru

Caused by: java.sql.SQLException: Field &#39;id&#39; doesn&#39;t have a default value

1.错误描述 org.hibernate.exception.GenericJDBCException: error executing work at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(Sql

Caused by: java.sql.SQLException: Column &#39;show_type&#39; not found

今天在处理个问题的时候遇到了这么个bug,难住了老半天.网上找了挺多资料.这是因为hibernate在别名上的不支持.处理方案是在jdbc数据库连接上计入了这么个配置. 绿色的相当于是个连接符. url="jdbc:mysql://localhost:3306/game_center?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true" 参考的博文是:http://blog.c

java连接Oracle数据库,从ResultSet中提取数据出现java.sql.sqlException结果集已耗尽

出现错误的原因是ResultSet中并没有任何东西,再调用next()方法就会出错,原因可能是oracle创建用户,表没有提交,commit即可