当前位置:编程学习 > JAVA >>

java内存管理的问题(代码效率)

下面的两段代码在查询大容量表的时候,会有效率上的差距吗? 第二种方法有没有可能造成栈溢出问题呢 代码片段一 stmt = con.prepareStatement(sql); stmt.setInt(1, category.getId()); rs = stmt.executeQuery(); Book book = null; while(rs.next()){ book = new Book(); book.setAuthor(rs.getString("author")); book.setAuthorSummary(rs.getString("author_summary")); book.setAddTime(rs.getLong("add_time")); book.setDangPrice(rs.getDouble("dang_price")); book.setFixedPrice(rs.getDouble("fixed_price")); book.setCatalogue(rs.getString("catalogue")); book.setPrintTime(rs.getLong("publish_time")); book.setPublishing(rs.getString("publishing")); book.setProductName(rs.getString("product_name")); books.add(book); } 代码片段二 stmt = con.prepareStatement(sql); stmt.setInt(1, category.getId()); rs = stmt.executeQuery(); while(rs.next()){ Bookbook = new Book(); book.setAuthor(rs.getString("author")); book.setAuthorSummary(rs.getString("author_summary")); book.setAddTime(rs.getLong("add_time")); book.setDangPrice(rs.getDouble("dang_price")); book.setFixedPrice(rs.getDouble("fixed_price")); book.setCatalogue(rs.getString("catalogue")); book.setPrintTime(rs.getLong("publish_time")); book.setPublishing(rs.getString("publishing")); book.setProductName(rs.getString("product_name")); books.add(book); }
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,