package com.moon.spring.support;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.RowSetDynaClass;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.moon.data.Kind;
import com.moon.data.Produces;
import com.moon.data.Shop;
import com.moon.spring.dao.ProducesDao;
public class ProducesSupport extends AllSupport implements ProducesDao {
public List getPro(int kindid){
List list = new ArrayList();
Session session = this.getSession();
Connection con = null;
try{
con = session.connection();
Statement st = con.createStatement();
String sql = "SELECT * FROM produces WHERE kind_id=" + kindid;
ResultSet rs = st.executeQuery(sql);
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
list = rsdc.getRows();
}catch(Exception e){
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return list;
}
/*
*功 能:添加商品
*参 数:商品实体类,类别编号,商店编号
*返回类型:true(成功)或false(失败)
*/
public boolean addProduce(Produces prod,int kid,Shop shop) {
// TODO Auto-generated method stub
boolean result = false;
Session session = this.getSession();
Transaction tran = session.beginTransaction();
Connection con = null;
try{
Kind kind = new Kind();
kind.setId(kid);
// con = session.connection();
// String sql = "select max(id) from produces";
// PreparedStatement pst = con.prepareStatement(sql);
// ResultSet rst = pst.executeQuery();
// if(rst.next()){
// int id = rst.getInt(1);
// sql = "insert into produces values(?,?,?,?,?,?,?,?)";
// pst = con.prepareStatement(sql);
// pst.setInt(1, ++ id);
// pst.setInt(2, sid);
// pst.setInt(3, kid);
// pst.setString(4, prod.getName());
// pst.setDouble(5, prod.getPrice());
// pst.setInt(6, prod.getCount());
// pst.setString(7, prod.getIntroduce());
// pst.setString(8, prod.getImage());
// int rows = pst.executeUpdate();
// result = rows > 0 ? true : false;
// }
// con = session.connection();
// String sql = "select max(id) from produces";
// String sql = "insert into produces(name,price,count,image,intrduce,shop_id) values(?,?,?,?,?,?)";
// PreparedStatement pst = con.prepareStatement(sql);
// ResultSet rst = pst.executeQuery();
// int id = rst.getInt(1);
// pst = con.prepareStatement(sql);
// pst.setInt(1, ++ id);
// pst.setInt(2, sid);
// pst.setInt(3, kid);
// pst.setString(4, prod.getName());
// pst.setDouble(5, prod.getPrice());
// pst.setInt(6, prod.getCount());
// pst.setString(7, prod.getIntroduce());
// pst.setString(8, prod.getImage());
Produces produces = new Produces();
produces.setKind(kind);
produces.setName(prod.getName());
produces.setCount(prod.getCount());
produces.setPrice(prod.getPrice());
produces.setImage(prod.getImage());
produces.setIntroduce(prod.getIntroduce());
produces.setShop(shop);
session.save(produces);
// pst.setString(1,prod.getName());
// pst.setDouble(2,prod.getPrice());
// pst.setInt(3,prod.getCount());
// pst.setString(4,prod.getImage());
// pst.setString(5,prod.getIntroduce());
// pst.setInt(6, sid);
//
// pst.executeUpdate();
result = true;
// int rows = pst.executeUpdate();
// result = rows > 0 ? true : false;
System.out.println("-------------------------------------OK");
tran.commit();
}catch(Exception ex){
tran.rollback();
ex.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return result;
}
/**
* 查询某类商品的总个数
* @param kindId 商品的类别
* @return 要查询的商品类别的商品的个数
*/
public int queryRowsByKind(int kindId){
int result = -1;
Session session = this.getSession();
Connection con = null;
try{
con = session.connection();
String sql = "SELECT count(1) FROM produces WHERE kind_id=" + kindId;
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
if(rs.next()){
result = rs.getInt(1);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return result;
}
/**
* 搜索与某个名字相匹配的商品的总个数
* @param name 所需搜索商品的名字
* @return 要搜索的商品的总个数
*/
public int queryRowsByName(String name){
int result = -1;
Session session = this.getSession();
Connection con = null;
try{
con = session.connection();
String sql = "SELECT count(1) FROM produces WHERE name like '%" + name + "%'";
//String sql = "select count(1) from produces where kind_id=" + 5;
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
if(rs.next()){
result = rs.getInt(1);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return result;
}
/**
* 查询某类商品的总个数
* @param kindId 商品的类别,start要查询的起始行号,end要查询的结束行号
* @return 要查询的商品
*/
public List queryAllByKind(int kindId,int start,int end){
List list = new ArrayList();
Session session = this.getSession();
Connection con = null;
try{
String sql = "select p.id,p.shop_id,p.name,p.price,p.intrduce,p.image from (select pp.*,rownum r from produces pp where rownum<=? and pp.kind_id=?) p where r>?";
con = session.connection();
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, end);
pst.setInt(2, kindId);
pst.setInt(3, start);
ResultSet rs = pst.executeQuery();
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
list = rsdc.getRows();
}catch(Exception e){
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return list;
}
/**
* 搜索与某名字品匹配的商品的总个数
* @param name 所需商品的名字,start要查询的起始行号,end要查询的结束行号
* @return 要查询的商品
*/
public List queryAllByName(String name,int start,int end){
List list = new ArrayList();
Session session = this.getSession();
Connection con = null;
try{
String sql = "select p.id,p.shop_id,p.name,p.price,p.intrduce,p.image from (select pp.*,rownum r from produces pp where rownum<=" + end + "and pp.name like '%" + name + "%') p where r>" + start;
/*String sql = "select p.id,p.shop_id,p.name,p.price,p.intrduce,p.image from (select pp.*,rownum r from produces pp where rownum<=? and pp.name like '%?%') p where r>?";
System.out.println(sql + "......: " + start + "******: " + end);
con = session.connection();
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, end);
pst.setString(2, name);
pst.setInt(3, start);*/
con = session.connection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(sql);
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
list = rsdc.getRows();
}catch(Exception e){
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return list;
}
/*
*功 能:查询一个商店的商品信息
*参 数:商店编号,查询多少条,查询页数
*返回类型:所有商品信息的集合
*/
public List queryAllById(int shopId,int rows,int curr) {
// TODO Auto-generated method stub
List list = new ArrayList();
Session session = this.getSession();
try{
session.beginTransaction();
// Connection con = session.connection();
// String sql = "select p.id,p.name,p.price,p.count,p.intrduce,p.image from (select p_.* ,rownum r from produces P_ where rownum<=? and p_.shop_id=
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
spring+struct+hibernate的网上购物网站 (502个子文件)
ProducesSupport.class 11KB
MD5Code.class 7KB
RecordSupport.class 7KB
ProduceAction.class 5KB
MessageSupport.class 5KB
ShopSupport.class 5KB
SendEmail.class 5KB
QuerymgAction.class 4KB
QueryUsermgAction.class 4KB
QueryShopmgAction.class 4KB
AllSupport.class 4KB
AddFavouriteAction.class 4KB
MessageAction.class 4KB
ProdService.class 4KB
HuifuAction.class 3KB
QueryKindAction.class 3KB
QueryUserAction.class 3KB
RegistAction.class 3KB
TradeMessage.class 3KB
LoginAction.class 3KB
BuyForm.class 3KB
LyTag.class 3KB
SingleshopAction.class 3KB
QueryAction.class 3KB
ShopAction.class 3KB
SearchAction.class 3KB
ShowKind.class 3KB
UserSupport.class 3KB
FindPassAction.class 3KB
UpAfficheForm.class 3KB
BookAction.class 3KB
NameTag.class 3KB
RecordAction.class 3KB
TradeStateAction.class 3KB
QueryFavAction.class 3KB
KindlookAction.class 3KB
ViewAction.class 3KB
UpdateUserForm.class 3KB
ShopServlet.class 3KB
UpdateProd.class 3KB
UpdateUserAction.class 3KB
Produces.class 2KB
HibernateSessionFactory.class 2KB
RecordServlet.class 2KB
BookServlet.class 2KB
QueryProAction.class 2KB
User.class 2KB
MessageForm.class 2KB
FavoriteSupport.class 2KB
BuyAction.class 2KB
RegistForm.class 2KB
ShopService.class 2KB
UpdateAfficheForm.class 2KB
ShowAffiche.class 2KB
AllKindAction.class 2KB
ProduceForm.class 2KB
AfficheAction.class 2KB
Shop.class 2KB
FindPassForm.class 2KB
ActivationUserAction.class 2KB
ConfirmAction.class 2KB
LogoutUserAction.class 2KB
DelAfficheAction.class 2KB
QueryUserMessAction.class 2KB
DelKindAction.class 2KB
DelUserAction.class 2KB
UpAfficheAction.class 2KB
Message.class 2KB
GoodsKindAction.class 2KB
Favorite.class 2KB
UserFilter.class 2KB
GoodsAction.class 2KB
GoodsForm.class 1KB
Test.class 1KB
KindSupport.class 1KB
QueryProSupport.class 1KB
HibernateUtils.class 1KB
AfficheForm.class 1KB
LoginForm.class 1KB
ShopForm.class 1KB
CodeFilter.class 1KB
DeleteCartAction.class 1KB
Account.class 1KB
Affiche.class 1KB
GoodsKindForm.class 1KB
Add_goodsKindForm.class 1KB
QueryProForm.class 1KB
AdminpayAction.class 1016B
Kind.class 988B
AfficheSupport.class 845B
SendEmail$1.class 822B
AddFavouriteForm.class 821B
TradeStateForm.class 815B
DeleteCartForm.class 815B
KindlookForm.class 809B
AllKindForm.class 806B
SearchForm.class 803B
ExportDB.class 761B
KindMethod.class 636B
AllDao.class 598B
共 502 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- cnjxhrh2013-03-14源码有错,不能编译,要修改
ernest201210
- 粉丝: 49
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功