📄 bookbean.java
字号:
package ebookshop.bean;
import java.io.Serializable;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import ebookshop.common.*;
import ebookshop.shopcart.BookDetails;
public class BookBean implements Serializable
{
private String bookName;
private String author;
private String publisher;
private Float price;
private String isbn;
private String description;
private boolean exist = false;
public BookBean(Integer bid,String bookName,String publisher,Float price,String description)
{
this.bookName=bookName;
this.publisher=publisher;
this.price=price;
this.description=description;
}
public BookBean()
{
}
public String getBookName(){return this.bookName;}
public String getPublisher(){return this.publisher;}
public String getAuthor(){return this.author;}
public Float getPrice(){return this.price;}
public String getIsbn(){return this.isbn;}
public String getDescription(){return this.description;}
public boolean getExist(){return this.exist;}
public void setBookName(String bookName){this.bookName=bookName;}
public void setAuthor(String author){this.author=author;}
public void setPublisher(String publisher){this.publisher=publisher;}
public void setPrice(Float price){this.price=price;}
public void setIsbn(String isbn){this.isbn=isbn;}
public void setDescription(String description){this.description=description;}
public void setExist(boolean exist){this.exist=exist;}
public Collection findBookByAuthor(String author) throws SQLException{
Connection con = DataConnect.getConnection("netbookdata");
String sql = "select * from book where author='"
+ author+"'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
BookBean book=null;
Collection b = new ArrayList();
while (rs.next()){
if(!this.exist) this.setExist(true);
book = new BookBean();
book.setIsbn(rs.getString("isbn"));
book.setBookName(rs.getString("bookName"));
book.setAuthor(rs.getString("author"));
book.setPrice(new Float(rs.getFloat("price")));
b.add(book);
}
rs.close();
stmt.close();
con.close();
return b;
}
public BookDetails findBookByISBN(String isbn) throws SQLException {
Connection con = DataConnect.getConnection("netbookdata");
String sql = "select * from book where isbn='"
+ isbn+"'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
BookDetails book=null;
while (rs.next()){
book=new BookDetails();
book.setIsbn(rs.getString("isbn"));
book.setBookName(rs.getString("bookName"));
book.setAuthor(rs.getString("author"));
book.setPrice(new Float(rs.getFloat("price")));
}
rs.close();
stmt.close();
con.close();
return book;
}
public Collection findBookByKeywords(String keyword){
Connection con = DataConnect.getConnection("netbookdata");
String sql="select * from book where bookName like '%"+keyword+ "%'";
Statement stmt = null;
try {
stmt = con.createStatement();
}
catch (SQLException ex) {
ex.printStackTrace();
}
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
}
catch (SQLException ex1) {
ex1.printStackTrace();
}
BookBean book=null;
Collection b = new ArrayList();
try {
while (rs.next()) {
if (!this.exist) {
this.setExist(true);
}
book = new BookBean();
book.setIsbn(rs.getString("isbn"));
book.setBookName(rs.getString("bookName"));
book.setAuthor(rs.getString("author"));
book.setPrice(new Float(rs.getFloat("price")));
b.add(book);
}
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
stmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
public String toString()
{
String str=null;
str=isbn+"\t"+ bookName +"\t"+author+"\t"+ publisher +"\t"+ price +"\t"+ description;
//System.out.println(str);
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -