package BookStore;
import java.util.*;
import java.sql.Connection;
import java.sql.ResultSet;
public class Book {
private int id = 0;
private int catId = 0;
private String name = null;
private float price = 0;
private float salePrice = 0;
private String descript = null;
private String author = null;
private String contents = null;
private String image = null;
public Book(){}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setCatId(int catId) {
this.catId = catId;
}
public int getCatId() {
return catId;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPrice(float price) {
this.price = price;
}
public float getPrice() {
return price;
}
public void setSalePrice(float salePrice) {
this.salePrice = salePrice;
}
public float getSalePrice() {
return salePrice;
}
public void setDescript(String descript) {
this.descript = descript;
}
public String getDescript() {
return descript;
}
public void setAuthor(String author) {
this.author = author;
}
public String getAuthor() {
return author;
}
public void setContents(String contents) {
this.contents = contents;
}
public String getContents() {
return contents;
}
public void setImage(String image) {
this.image = image;
}
public String getImage() {
return image;
}
public static Vector SearchBook(DB db,int mode,int bookCat,String field,String keyword) throws Exception{
Vector bookList = new Vector();
ResultSet rs;
String strSql=null;
String sField=null;
if (mode==1 ) {
strSql = "select * from book where catid=" + bookCat;
}
else{
if (field.equals("1")) sField="name";
else if(field.equals("2")) sField="author";
strSql = "select * from book where " + sField +" like '%" + keyword +"%' order by id";
}
/* if (bookCat==0 ) {
strSql = "select * from book where 1=1 ";
}
else{
strSql = "select * from book where catid=" + bookCat;
}
if (keyword==null||keyword==""){
strSql = strSql + " order by id";
}
else{
if (field.equals("1")) sField="name";
else if(field.equals("2")) sField="author";
strSql = strSql + " and " + sField +" like '%" + keyword +"%' order by id";
}
*/
rs = db.OpenSql(strSql);
while (rs.next()){
Book book = new Book();
book.setId(rs.getInt("id")) ;
book.setName(rs.getString("name")) ;
book.setAuthor(rs.getString("author")) ;
book.setPrice(rs.getInt("price")) ;
book.setSalePrice(rs.getInt("saleprice")) ;
bookList.add(book);
}
System.out.println("bookList: "+bookList.size());
return bookList;
}
public static Book GetDetail(DB db,int bookId) throws Exception{
ResultSet rs;
String strSql=null;
String rplContent=null;
strSql = "select * from book where id=" + bookId;
rs = db.OpenSql(strSql);
Book book = new Book();
if (rs.next()){
book.setId(rs.getInt("id")) ;
book.setName(rs.getString("name")) ;
book.setAuthor(rs.getString("author")) ;
book.setPrice(rs.getInt("price")) ;
book.setSalePrice(rs.getInt("saleprice")) ;
book.setImage(rs.getString("image")) ;
rplContent = rs.getString("descript");
rplContent = rplContent.replaceAll("\n","<br>");
book.setDescript(rplContent) ;
rplContent = rs.getString("contents");
rplContent = rplContent.replaceAll("\n","<br>");
book.setContents(rplContent) ;
}
return book;
}
public static int GetBookCount(DB db,int mode,int bookCat,String field,String keyword) throws Exception{
ResultSet rs;
String strSql=null;
String sField=null;
int iRecordCount=0;
if (mode==1 ) {
strSql = "select count(*) from book where catid=" + bookCat;
}
else{
if (field.equals("1")) sField="name";
else if(field.equals("2")) sField="author";
strSql = "select count(*) from book where " + sField +" like '%" + keyword +"%' order by id";
}
rs = db.OpenSql(strSql);
if ( rs.next()) {
iRecordCount=rs.getInt(1);
}
return iRecordCount;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
网上书店STRUTS+SQLSERVER+JSP (121个子文件)
Book.class 4KB
AddrConfirmAction.class 3KB
Order.class 3KB
BookBuyAction.class 3KB
PageCtrlAction.class 3KB
BookSearchAction.class 2KB
LoginAction.class 2KB
User.class 2KB
OrderDelAction.class 2KB
RegistAction.class 2KB
DetailAction.class 2KB
UpdateShopCartAction.class 2KB
BookDetailAction.class 2KB
DB.class 2KB
OrderHistoryAction.class 2KB
BookCat.class 1KB
SearchStatus.class 1KB
ClearShopCartAction.class 1KB
Constants.class 995B
ShopCart.class 951B
MyRequestProcessor.class 708B
new.css 5KB
style.css 2KB
banner.gif 19KB
bookTop.gif 10KB
book_046.gif 5KB
007.gif 4KB
book_001.gif 4KB
book_029.gif 2KB
book_020.gif 2KB
book800_005.gif 2KB
book_035.gif 2KB
book_003.gif 2KB
book_042.gif 2KB
00-1.gif 2KB
00-2.gif 2KB
book_039.gif 2KB
book_011.gif 2KB
b10025.gif 2KB
book_002.gif 2KB
book_027.gif 2KB
book_040.gif 1KB
book_logo.gif 1KB
book800_19_08.gif 985B
book_043.gif 790B
ti1.gif 774B
ti2.gif 772B
book_006.gif 766B
book_008.gif 730B
book_007.gif 726B
book_005.gif 721B
book_013.gif 705B
book_032.gif 690B
book_012.gif 689B
book_038.gif 688B
book_028.gif 666B
book_026.gif 565B
button002.gif 550B
button005.gif 547B
view.gif 386B
pwd.gif 311B
stars4.gif 233B
book_bg2.gif 197B
book800_081.gif 192B
order.gif 180B
book.gif 84B
book_004.gif 73B
book_041.gif 63B
spacer.gif 43B
kong.gif 43B
struts.jar 514KB
antlr.jar 379KB
commons-collections.jar 171KB
commons-beanutils.jar 116KB
commons-digester.jar 107KB
commons-validator.jar 82KB
jakarta-oro.jar 64KB
commons-logging.jar 37KB
commons-fileupload.jar 22KB
Book.java 5KB
ShopCartForm.java 4KB
AddrConfirmAction.java 3KB
BookSearchAction.java 3KB
Order.java 3KB
BookBuyAction.java 3KB
FirstAction.java 3KB
PageCtrlAction.java 2KB
User.java 2KB
RegistAction.java 2KB
OrderDelAction.java 2KB
LoginAction.java 2KB
UpdateShopCartAction.java 2KB
DetailAction.java 2KB
BookDetailAction.java 1KB
OrderHistoryAction.java 1KB
DB.java 1KB
ClearShopCartAction.java 1KB
SearchStatus.java 1KB
BookCat.java 1KB
Constants.java 1KB
共 121 条
- 1
- 2
资源评论
- 孤独的根号三2013-04-24基本符合要求,不过要修改一下错误。
- gb19941282013-12-12有点小问题,改正后可用
lutherhua
- 粉丝: 12
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功