标签:
public List<Book> getBooks(String name) {
List<Book> books = ArrayList<Book>();
String sql = "select * from Book where name?";
try {
conn = getConnection(); // 获取连接
stmt = conn.preapareStatement(sql); // 命名对象
stmt.setString(1, ‘%‘ + name + ‘%‘); // 参数设置
rs = stmt.executeQuery();
while (rs.next()) {
Book book = new Book();
book.setId(rs.getInt(1));
book.setName(rs.getString(2));
list.add(book);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(conn, stmt, rs);
}
return books;
}
标签:
原文地址:http://www.cnblogs.com/kongqinyuan/p/5258814.html