package com.quicklyteam.easybuy.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.quicklyteam.easybuy.dao.BaseDao;
import com.quicklyteam.easybuy.dao.ProductDao;
import com.quicklyteam.easybuy.entity.Product;
/**
* 商品数据访问层实现类
* @author Yzw
* @version 2013-5-10
*/
public class ProductDaoImpl extends BaseDao implements ProductDao {
/**
* 通过商品状态获取部分商品
*/
public List<Product> getProductsByStatus(int status, int number) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
List<Product> productList = new ArrayList<Product>();
String sql = "select * from easybuy_product where ep_status = ? and rownum <= ?";
try {
ps = conn.prepareStatement(sql);
ps.setInt(1, status);
ps.setInt(2, number);
rs = ps.executeQuery();
while (rs.next()) {
Product product = new Product(rs.getInt("ep_id"), rs.getString("ep_name"), rs.getString("ep_description"),
rs.getDouble("ep_price"), rs.getInt("ep_stock"), rs.getInt("ep_status"), rs.getInt("epc_id"),
rs.getInt("epc_child_id"), rs.getString("ep_file_name"), 1);
productList.add(product);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, rs);
}
return productList;
}
/**
* 通过类别获取商品,并限制数据范围
*/
public List<Product> getProductsByCategory(int id, int level, int pageSize, int pageIndex) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
List<Product> productList = new ArrayList<Product>();
String sql = "select *\n" + " from (select rownum r, t.*\n"
+ " from (select * from easybuy_product where epc_id = ? and ep_status != -1) t\n"
+ " where rownum <= ? * ?)\n" + " where r > (? - 1) * ?";
if (level == 2) {
sql = "select *\n" + " from (select rownum r, t.*\n"
+ " from (select * from easybuy_product where epc_child_id = ? and ep_status != -1) t\n"
+ " where rownum <= ? * ?)\n" + " where r > (? - 1) * ?";
}
if (id == -1 && level == -1) {
sql = "select *\n" + " from (select rownum r, t.*\n"
+ " from (select * from easybuy_product where ep_status != -1) t\n" + " where rownum <= ? * ?)\n"
+ " where r > (? - 1) * ?";
}
try {
ps = conn.prepareStatement(sql);
if (id == -1 && level == -1) {
ps.setInt(1, pageIndex);
ps.setInt(2, pageSize);
ps.setInt(3, pageIndex);
ps.setInt(4, pageSize);
} else {
ps.setInt(1, id);
ps.setInt(2, pageIndex);
ps.setInt(3, pageSize);
ps.setInt(4, pageIndex);
ps.setInt(5, pageSize);
}
rs = ps.executeQuery();
while (rs.next()) {
Product product = new Product(rs.getInt("ep_id"), rs.getString("ep_name"), rs.getString("ep_description"),
rs.getDouble("ep_price"), rs.getInt("ep_stock"), rs.getInt("ep_status"), rs.getInt("epc_id"),
rs.getInt("epc_child_id"), rs.getString("ep_file_name"), 1);
productList.add(product);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, rs);
}
return productList;
}
/**
* 获取指定商品类别ID的商品数量
*/
public int getCountByCategory(int id, int level) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select count(*) from easybuy_product where epc_id = ? and ep_status != -1";
if (level == 2) {
sql = "select count(*) from easybuy_product where epc_child_id = ? and ep_status != -1";
}
if (id == -1 && level == -1) {
sql = "select count(*) from easybuy_product where ep_status != -1";
}
try {
ps = conn.prepareStatement(sql);
if (id != -1 && level != -1) {
ps.setInt(1, id);
}
rs = ps.executeQuery();
if (rs.next()) {
return rs.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, rs);
}
return 0;
}
/**
* 获取可以显示的总页数
*/
public int getTotalPages(int count, int pageSize) {
// TODO Auto-generated method stub
return count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
}
/**
* 通过ID获取商品信息
*/
public Product getProductById(int id) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select * from easybuy_product where ep_id = ?";
try {
ps = conn.prepareStatement(sql);
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.next()) {
Product product = new Product(rs.getInt("ep_id"), rs.getString("ep_name"), rs.getString("ep_description"),
rs.getDouble("ep_price"), rs.getInt("ep_stock"), rs.getInt("ep_status"), rs.getInt("epc_id"),
rs.getInt("epc_child_id"), rs.getString("ep_file_name"), 1);
return product;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, rs);
}
return null;
}
/**
* 通过ID删除商品
*/
public int deleteById(int id, int columnType) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
String sql = "delete easybuy_product where";
if (columnType == 1) {
sql += " ep_id = ?";
} else if (columnType == 2) {
sql += " epc_id = ?";
} else if (columnType == 3) {
sql += " epc_child_id = ?";
} else {
return 0;
}
try {
ps = conn.prepareStatement(sql);
ps.setInt(1, id);
return ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, null);
}
return 0;
}
/**
* 添加一条商品
*/
public int insert(Product product) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
String sql = "insert into easybuy_product values(easybuy_product_seq.nextval,?,?,?,?,?,?,?,?)";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, product.getName());
ps.setString(2, product.getDescription());
ps.setDouble(3, product.getPrice());
ps.setInt(4, product.getStock());
ps.setInt(5, product.getStatus());
ps.setInt(6, product.getEpcId());
ps.setInt(7, product.getEpcChildId());
ps.setString(8, product.getFileName());
return ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, null);
}
return 0;
}
/**
* 更新一条商品
*/
public int update(Product product) {
// TODO Auto-generated method stub
Connection conn = getConnection();
PreparedStatement ps = null;
String sql = "update easybuy_product set ep_name=?,ep_description=?,ep_price=?,ep_stock=?,ep_status=?,epc_id=?,epc_child_id=?,ep_file_name=? where ep_id=?";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, product.getName());
ps.setString(2, product.getDescription());
ps.setDouble(3, product.getPrice());
ps.setInt(4, product.getStock());
ps.setInt(5, product.getStatus());
ps.setInt(6, product.getEpcId());
ps.setInt(7, product.getEpcChildId());
ps.setString(8, product.getFileName());
ps.setInt(9, product.getId());
return ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
closeAll(conn, ps, null);
}
return 0;
}
/**
* 禁
没有合适的资源?快使用搜索试试~ 我知道了~
easybuy项目一个jsp+servlet+javabean的一个实例
共288个文件
jpg:81个
java:75个
class:75个
5星 · 超过95%的资源 需积分: 35 308 下载量 63 浏览量
2013-05-31
15:41:02
上传
评论 2
收藏 2.34MB ZIP 举报
温馨提示
使用java做的一个网上商城的开源项目-易买网。该项目使用jsp+servlet+javabean实现。其中用到了ajax技术。文件中包括了源代码和建表语句,数据库用的是oracle,源代码中没有上传所需的jar包,jar包需要jdbc驱动包和smartupload的jar包,可以自己到网上进行下载。该例子共学习jsp技术使用,不适合做开源的项目。
资源推荐
资源详情
资源评论
收起资源包目录
easybuy项目一个jsp+servlet+javabean的一个实例 (288个子文件)
ProductDaoImpl.class 7KB
NewsDaoImpl.class 6KB
OrderDaoImpl.class 5KB
UserDaoImpl.class 5KB
CommentDaoImpl.class 5KB
ModifyProductServlet.class 5KB
AddProductServlet.class 5KB
ProductCategoryDaoImpl.class 4KB
ProductDetailServlet.class 3KB
BuyServlet.class 3KB
ProductPagingServlet.class 3KB
SettleAccountServlet.class 3KB
GetOrderServlet.class 3KB
GetMainPageDataServlet.class 3KB
User.class 3KB
Product.class 3KB
RegisterServlet.class 3KB
LoginServlet.class 2KB
GetProductCategory.class 2KB
GetNewsServlet.class 2KB
GetCommentServlet.class 2KB
GetProductDetailServlet.class 2KB
UserBizImpl.class 2KB
OrderDetailDaoImpl.class 2KB
ModifyCommentServlet.class 2KB
AddCommentServlet.class 2KB
CommentDetailServlet.class 2KB
ModifyBuyCountServlet.class 2KB
ModifyUserServlet.class 2KB
DelShoppingTrolleyServlet.class 2KB
OrderDetailServlet.class 2KB
ProductBizImpl.class 2KB
GetUserDetailServlet.class 2KB
NewsDetailServlet.class 2KB
ModifyProductCategory.class 2KB
ModifyOrderServlet.class 2KB
ValidateNewsTitleServlet.class 2KB
NewsBizImpl.class 2KB
OrderBizImpl.class 2KB
ModifyNewsServlet.class 2KB
AddProductCategory.class 2KB
DeleteProductCategoryServlet.class 2KB
ProductCategoryBizImpl.class 2KB
Comment.class 2KB
GetUsersServlet.class 2KB
CheckLoginServlet.class 2KB
DeleteCommentServlet.class 2KB
Order.class 2KB
ValidateUserNameServlet.class 2KB
AddNewsServlet.class 2KB
DeleteUserServlet.class 2KB
DeleteProductServlet.class 2KB
DeleteOrderServlet.class 2KB
DeleteNewsServlet.class 2KB
CommentBizImpl.class 2KB
BaseDao.class 2KB
News.class 1KB
LogoutServlet.class 1KB
OrderDetail.class 1KB
ProductCategory.class 1KB
OrderDetailBizImpl.class 857B
ProductDao.class 660B
ProductBiz.class 637B
NewsDao.class 627B
UserDao.class 602B
NewsBiz.class 598B
UserBiz.class 581B
OrderDao.class 558B
OrderBiz.class 546B
CommentDao.class 542B
ProductCategoryDao.class 504B
ProductCategoryBiz.class 493B
CommentBiz.class 466B
OrderDetailDao.class 285B
OrderDetailBiz.class 201B
.classpath 598B
org.eclipse.wst.common.component 459B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 13KB
Thumbs.db 47KB
Thumbs.db 9KB
logo.gif 1KB
ProductDaoImpl.java 8KB
NewsDaoImpl.java 6KB
OrderDaoImpl.java 6KB
UserDaoImpl.java 6KB
CommentDaoImpl.java 5KB
ProductCategoryDaoImpl.java 4KB
ModifyProductServlet.java 4KB
AddProductServlet.java 4KB
ProductPagingServlet.java 4KB
ProductDetailServlet.java 3KB
BuyServlet.java 3KB
GetOrderServlet.java 3KB
GetMainPageDataServlet.java 3KB
SettleAccountServlet.java 3KB
GetCommentServlet.java 3KB
RegisterServlet.java 3KB
GetProductCategory.java 3KB
GetNewsServlet.java 2KB
共 288 条
- 1
- 2
- 3
huaishuiyipen
- 粉丝: 2
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页