如何从结果集中遍历得到一条条的数据?

平常我们遍历结果集的时候,都必须创建一个实体bean,然后将结果集遍历的时候通过set方法放到这个实体bean对象中.

1 String sql="select * from book"; 2 try{ 3 Connection con = MyConnection.getConnection(); 4 Statement statement = con.createStatement(); 5 ResultSet resultSet = statement.executeQuery(sql); 6 // ResultSetMetaData rsmd = resultSet.getMetaData(); 7 // int count = rsmd.getColumnCount(); 8 while(resultSet.next()) 9 { 10 Book book = new Book(); 11 book.setBookName(resultSet.getString("bookName")); 12 book.setPrice(resultSet.getString("price")); 13 book.setPicUrl(resultSet.getString("picUrl")); 14 list.add(book); 15 }catch(SQLException e) 16 { e.printStackTrace(); 17 } catch (ClassNotFoundException e) { 18 e.printStackTrace(); 19 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzsywd.html