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; }
浙公网安备 33010602011771号