当前位置: 代码迷 >> Java Web开发 >> 无法接收函数返回的list解决办法
  详细解决方案

无法接收函数返回的list解决办法

热度:301   发布时间:2016-04-17 10:46:35.0
无法接收函数返回的list
网页没有显示任何错误,运行正常但是topices始终为空。
排除数据库语句错误,因为我试过
排除DB类中方法的错误,因为我在其他的页面中使用过

网页上调用的代码:
Java code
List<topic> topices = new ArrayList<topic>();    topices=topic.getTopic();

打印topices.size()的大小 显示“0”!

getTopic()方法的代码:
Java code
public static List<topic> getTopic() {        List<topic> topices = new ArrayList<topic>();        Connection conn = DB.getConn();        String sql = "select * from topic";        Statement stmt = DB.getStatement(conn);        ResultSet rs = DB.getResultSet(stmt, sql);        try {            while (rs.next()) {                topic t = new topic();                t.setSid(rs.getInt("sid"));                t.setUid(rs.getInt("uid"));                t.setTitle(rs.getString("title"));                t.setContent(rs.getString("content"));                t.setPosttime(rs.getTimestamp("posttime"));                t.setClickcount(rs.getInt("clickcount"));                t.setLastreply(rs.getTimestamp("lastreply"));                t.setIstop(rs.getBoolean("istop"));                t.setIsgood(rs.getBoolean("isgood"));                t.setLevel(rs.getInt("level"));                topices.add(t);            }        } catch (SQLException e) {            e.printStackTrace();        } finally {            DB.close(rs);            DB.close(stmt);            DB.close(conn);        }        return topices;    }


------解决方案--------------------
有可能是你的循环模块出现错误了。你try只catch了SQLException ,所以即使报错也不会显示出来。把SQLException 换成Exception试试。
------解决方案--------------------
你贴的代码没问题,,数据库表里面到底有没有数据。。。。。
------解决方案--------------------
在return之前设个断点或打印看看有没有数据。
------解决方案--------------------
debug试看看.
------解决方案--------------------
在while里边打印试试有没有数据 还有觉得那个Statement语句是不是应该用预编译的preparedStatement
  相关解决方案