怎么遍历ResultSet中的数据
1个回答
展开全部
这个是御衡servlet和java bean 一起写的,我是这么做的,
String sql="select * from book";
try{
Connection con = MyConnection.getConnection();
Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
//镇颂做 ResultSetMetaData rsmd = resultSet.getMetaData();
// int count = rsmd.getColumnCount();
while(resultSet.next()){
Book book = new Book();
book.setBookName(resultSet.getString("bookName"));
book.setPrice(resultSet.getString("price"));
book.setPicUrl(resultSet.getString("picUrl"));
list.add(book);
}
}catch(SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
但是我不樱没是很满意,有些总是弄不懂,是javaWeb的问题
String sql="select * from book";
try{
Connection con = MyConnection.getConnection();
Statement statement = con.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
//镇颂做 ResultSetMetaData rsmd = resultSet.getMetaData();
// int count = rsmd.getColumnCount();
while(resultSet.next()){
Book book = new Book();
book.setBookName(resultSet.getString("bookName"));
book.setPrice(resultSet.getString("price"));
book.setPicUrl(resultSet.getString("picUrl"));
list.add(book);
}
}catch(SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
但是我不樱没是很满意,有些总是弄不懂,是javaWeb的问题
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |