package com.jspdev.ch12;
import java.sql.*;
import java.util.*;
import java.io.*;
import com.jspdev.util.*;
/**
*ProductBean包含和Product表相关的操作
*/
public class ProductBean
{
private Connection con;
//构造方法,获得数据库的连接。
public ProductBean()
{
this.con=DataBaseConnection.getConnection();
}
/**
*搜索所有的商品信息。
*返回由Product值对象组成的Collection
*/
public Collection getAllProduct()throws Exception
{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from Products");
Collection ret=new ArrayList();
while(rst.next())
{
Product temp=new Product();
temp.setProductId(rst.getString("productid"));
temp.setCategoryId(rst.getString("category"));
temp.setName(rst.getString("name"));
temp.setDescription(rst.getString("descn"));
temp.setProducer(rst.getString("producer"));
temp.setPrice(rst.getString("price"));
ret.add(temp);
}
con.close();
return ret;
}
/**
*按照商品的类别查找商品,
*返回由Product值对象组成的Collection
*/
public Collection getProductByCategory(String categoryId)throws Exception
{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from Products where category='"+categoryId+"'");
Collection ret=new ArrayList();
while(rst.next())
{
Product temp=new Product();
temp.setProductId(rst.getString("productid"));
temp.setCategoryId(rst.getString("category"));
temp.setName(rst.getString("name"));
temp.setDescription(rst.getString("descn"));
temp.setProducer(rst.getString("producer"));
temp.setPrice(rst.getString("price"));
ret.add(temp);
}
con.close();
return ret;
}
/**
*按照出版社查找图书,
*返回由Product值对象组成的Collection
*/
public Collection getProductByProducer(String producerId)throws Exception
{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from Products where producer='"+producerId+"'");
Collection ret=new ArrayList();
while(rst.next())
{
Product temp=new Product();
temp.setProductId(rst.getString("productid"));
temp.setCategoryId(rst.getString("category"));
temp.setName(rst.getString("name"));
temp.setDescription(rst.getString("descn"));
temp.setProducer(rst.getString("producer"));
temp.setPrice(rst.getString("price"));
ret.add(temp);
}
con.close();
return ret;
}
public Collection getProductByName(String nameId)throws Exception
{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from Products where name like '%"+nameId+"%' ");
Collection ret=new ArrayList();
while(rst.next())
{
Product temp=new Product();
temp.setProductId(rst.getString("productid"));
temp.setCategoryId(rst.getString("category"));
temp.setName(rst.getString("name"));
temp.setDescription(rst.getString("descn"));
temp.setProducer(rst.getString("producer"));
temp.setPrice(rst.getString("price"));
ret.add(temp);
}
con.close();
return ret;
}
/**
*添加一个商品,使用Product值对象作为参数传给这个方法。
*/
public void addProduct(Product product)throws Exception
{
PreparedStatement pstmt=con.prepareStatement("insert into products values(?,?,?,?,?,?)");
pstmt.setString(1,product.getProductId());
pstmt.setString(2,product.getCategoryId());
pstmt.setString(3,product.getName());
pstmt.setString(4,product.getProducer());
pstmt.setString(5,product.getPrice());
pstmt.setString(6,product.getDescription());
pstmt.execute();
}
/**
*更改商品的信息,使用Product值对象作为参数传给这个方法。
*/
public void modifyProduct(Product product)throws Exception
{
PreparedStatement pstmt=con.prepareStatement("update products set category=?,name=?, producer=?,price=?,descn=? where productid=?");
pstmt.setString(1,product.getCategoryId());
pstmt.setString(2,product.getName());
pstmt.setString(3,product.getProducer());
pstmt.setString(4,product.getPrice());
pstmt.setString(5,product.getDescription());
pstmt.setString(6,product.getProductId());
pstmt.execute();
}
/**
*删除没个商品,指定商品的ID
*/
public void deleteProduct(String productId)throws Exception
{
Statement stmt=con.createStatement();
stmt.execute("delete from products where productid='"+productId+"'");
}
/**
*返回给定ProductId的商品的信息,
*返回的是值对象
*/
public Product getProductInfo(String productId)throws Exception
{
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from products where productid='"+productId+"'");
Product product=null;
while(rst.next())
{
product=new Product();
product.setProductId(rst.getString("productid"));
product.setCategoryId(rst.getString("category"));
product.setName(rst.getString("name"));
product.setDescription(rst.getString("descn"));
product.setProducer(rst.getString("producer"));
product.setPrice(rst.getString("price"));
}
return product;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jsp+sql 图书馆管理系统,里面含doc文档,毕业论文 含有使用说明
共35个文件
jsp:11个
class:9个
java:9个
需积分: 15 28 下载量 98 浏览量
2010-01-02
16:20:19
上传
评论
收藏 155KB RAR 举报
温馨提示
jsp+sql编写的图书馆管理系统,可以做毕业论文 里面含doc文档,只要自己该一改就可以做毕业论文 含有使用说明,一定值得下载
资源推荐
资源详情
资源评论
收起资源包目录
Jsp+access图书馆管理系统.rar (35个子文件)
wy
product
deleteProduct.jsp 2KB
viewProduct.jsp 1KB
modifyProduct.jsp 2KB
searchProductByName.jsp 2KB
viewCategory.jsp 1KB
modifyProduct_pro.jsp 2KB
trans.jsp 708B
error.jsp 330B
searchProductByProducer.jsp 2KB
addProduct.jsp 2KB
searchProductByCategory.jsp 2KB
pic
pic_11.gif 9KB
pic_08.gif 11KB
WEB-INF
web.xml 1KB
classes
AddServlet.java 2KB
UpdateServlet.java 2KB
DataBaseConnection.java 552B
com
jspdev
ch12
ProductBean.class 4KB
Product.class 1KB
ViewCategory.class 1KB
ADUBean.class 1KB
Category.class 843B
util
DataBaseConnection.java 564B
DataBaseConnection.class 642B
myservlet
AddServlet.class 2KB
UpdateServlet.class 2KB
DeteleServlet.class 1KB
Category.java 725B
ViewCategory.java 877B
DeteleServlet.java 1KB
Product.java 1KB
ProductBean.java 5KB
lib
mm.mysql-2.0.4-bin.jar 107KB
index.html 2KB
wy.mdb 176KB
共 35 条
- 1
资源评论
jiangchao008
- 粉丝: 0
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功