?? book.java
字號:
package com.ascenttech.ebookstore.bean;
import java.sql.*;
import java.util.*;
import com.ascenttech.ebookstore.shopcart.BookDetails;
import com.ascenttech.ebookstore.util.*;
public class Book {
//data
private String isbn;
private String title;
private String author;
private float price;
private boolean exist = false;
private int count=0;
// method
public Book(String isbn, String title, float price) {
this.isbn = isbn;
this.title = title;
this.price = price;
this.count=0;
}
//constructor
public Book() {
}
// getXXX()/setXXX(){}
public String getIsbn(){return this.isbn;}
public String getTitle(){return this.title;}
public String getAuthor(){return this.author;}
public float getPrice(){return this.price;}
public boolean getExist(){return this.exist;}
public int getCount(){return this.count;}
public void setIsbn(String isbn){this.isbn = isbn;}
public void setTitle(String title){this.title = title;}
public void setAuthor(String author){this.author = author;}
public void setPrice(float price) {this.price = price;}
public void setExist(boolean exist){this.exist=exist;}
public void setCount(int count){this.count = count;}
public BookDetails findBookByISBN(String isbn) throws SQLException {
Connection con = DataAccess.getConnection();
String sql = "select * from ebs_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.setTitle(rs.getString("title"));
book.setAuthor(rs.getString("author"));
book.setPrice(rs.getFloat("price"));
}
rs.close();
stmt.close();
con.close();
return book;
}
public Collection findBookByAuthor(String author) throws SQLException{
Connection con = DataAccess.getConnection();
String sql = "select * from ebs_book where author='"
+ author+"'";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
Book book=null;
Collection b = new ArrayList();
while (rs.next()){
if(!this.exist) this.setExist(true);
book = new Book();
book.setIsbn(rs.getString("isbn"));
book.setTitle(rs.getString("title"));
book.setAuthor(rs.getString("author"));
book.setPrice(rs.getFloat("price"));
b.add(book);
}
rs.close();
stmt.close();
con.close();
return b;
}
public Collection findBookByKeywords(String keyword){
Connection con = DataAccess.getConnection();
String sql="select * from ebs_book where title 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();
}
Book book=null;
Collection b = new ArrayList();
try {
while (rs.next()) {
if (!this.exist) {
this.setExist(true);
}
book = new Book();
book.setIsbn(rs.getString("isbn"));
book.setTitle(rs.getString("title"));
book.setAuthor(rs.getString("author"));
book.setPrice(rs.getFloat("price"));
b.add(book);
}
}
catch (SQLException ex2) {
ex2.printStackTrace();
}
return b;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -