public class select {
public List XiuGai_select(String keyword){
List list=new ArrayList();
Connection conn = null;
Statement stmt = null;
String sql=null;
ResultSet res = null;
getConnection b=new getConnection();
conn=b.getconnection();
sql="select * from book where bookName like'%"+keyword+"%'";
try {
stmt = conn.createStatement();
res=stmt.executeQuery(sql);
while (res.next()) { //如果结果集不为空,那么取出值输出
int id = res.getInt("id");
String bookName= res.getString("bookName");
String author= res.getString("author");
String publisher= res.getString("publisher");
int isBorrow=res.getInt("isBorrow");
int isRenew=res.getInt("isRenew");
Date dateOfBorrow=res.getDate("dateOfBorrow");
int numberOfBook=res.getInt("numberOfBook");
int numberOfNow=res.getInt("numberOfNow");
int userId=res.getInt("userId");
Book book = new Book(id,bookName,author,publisher,isBorrow,isRenew,dateOfBorrow,numberOfBook,numberOfNow,userId);
list.add(book);
System.out.println(id);
System.out.println(bookName);
System.out.println(author);
System.out.println(publisher);
}
for(int i=0;i<list.size();i++){
Book book =(Book)list.get(i);
System.out.println("uuuuuuuu"+book.getAuthor());
}
res.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
System.out.println(" 数据库查询操作失败!");
}
System.out.println(" 查询数据成功!");
return list;
}
/*public static void main(String[] args) {
select a=new select();
a.XiuGai_select("王");
}*/
}