要做一个图书管理系统,下面是我写的一个dao类里的获取全部图书的方法,现在我想用BookManger类里用一个JTable表格显示,该怎么实现,网上看了很多例子看不懂啊,求大神给代码publicL...
要做一个图书管理系统,下面是我写的一个dao类里的获取全部图书的方法,现在我想用 BookManger类里用一个JTable表格显示,该怎么实现,网上看了很多例子看不懂啊,求大神给代码
public List getAllBook(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pt = null;
ResultSet rs = null;
boolean flag = false;
con = Conn.getConnection();
try {
pt = con.prepareStatement("select * from booksm");
rs = pt.executeQuery();
while(rs.next()){
Book book = new Book();
book.setId(rs.getInt(1));
book.setISBNNum(rs.getInt(2));
book.setName(rs.getString(3));
book.setAuthor(rs.getString(4));
book.setPress(rs.getString(5));
book.setType(rs.getString(6));
book.setPrice(rs.getDouble(7));
book.setInventory(rs.getInt(8));
book.setSum(rs.getInt(9));
list.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
展开