package biz.yoycity.business.dao.j2ee4;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import biz.yoycity.business.bean.j2ee4.TradeInformation;
import biz.yoycity.business.bean.j2ee4.TradeSort;
import biz.yoycity.business.factory.ConnectionFactory;
public class TradeSortDAO {
private Connection con=null;
private PreparedStatement ps=null;
private ResultSet rs=null;
//对所有商品大类别的描述
public List<TradeSort> getSorts()
{
List<TradeSort> sorts=new ArrayList<TradeSort>();
TradeSort sort=null;
try {
con=ConnectionFactory.getConnection();
ps=con.prepareStatement("select * from Trade_sort where father=0 ");
rs=ps.executeQuery();
while(rs.next())
{
sort=new TradeSort(rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4));
sorts.add(sort);
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
ConnectionFactory.close(rs);
ConnectionFactory.close(ps);
ConnectionFactory.close(con);
}
return sorts;
}
//根据大类别查询所有小类
public List<TradeSort> getSort2All(String father)
{
List<TradeSort> list=new ArrayList<TradeSort> ();
TradeSort sort=null;
if(father.equals("all"))
{
}
else
{
try {
con=ConnectionFactory.getConnection();
ps=con.prepareStatement("select * from trade_sort where father=?");
int tid=Integer.parseInt(father);
ps.setInt(1, tid);
rs=ps.executeQuery();
TradeSort sort2=new TradeSort(null,1,"所有种类",null);
list.add(sort2);
while(rs.next())
{
sort=new TradeSort(rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4));
list.add(sort);
}
} catch (Exception e) {
System.out.println("查询小类问题");
}
finally{
ConnectionFactory.close(con);
ConnectionFactory.close(ps);
ConnectionFactory.close(rs);
}
}
return list;
}
//top应用中的 根据大类别 查询 所有小类
public List<TradeSort> getSortAll(int father)
{
List<TradeSort> list=new ArrayList<TradeSort> ();
TradeSort sort=null;
try {
con=ConnectionFactory.getConnection();
ps=con.prepareStatement("select * from trade_sort where father=?");
ps.setInt(1, father);
rs=ps.executeQuery();
while(rs.next())
{
sort=new TradeSort(rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4));
list.add(sort);
}
} catch (Exception e) {
System.out.println("查询小类问题");
}
finally{
ConnectionFactory.close(con);
ConnectionFactory.close(ps);
ConnectionFactory.close(rs);
}
return list;
}
//根据大类别 查询 一个小类
public String getSort2(int tid)
{
String content=new String();
try {
con=ConnectionFactory.getConnection();
ps=con.prepareStatement("select * from trade_sort where Tid=?");
ps.setInt(1, tid);
rs=ps.executeQuery();
if(rs.next())
{
content=rs.getString("Tid")+","+rs.getString("TName");
}
} catch (Exception e) {
System.out.println("查询小类问题");
}
finally{
ConnectionFactory.close(con);
ConnectionFactory.close(ps);
ConnectionFactory.close(rs);
}
return content;
}
//根据类别id 查询商品的名称
public String getSortName(int tid)
{
String content=new String();
try {
con=ConnectionFactory.getConnection();
ps=con.prepareStatement("select * from trade_sort where Tid=?");
ps.setInt(1, tid);
rs=ps.executeQuery();
if(rs.next())
{
content=rs.getString("TName");
}
} catch (Exception e) {
System.out.println("查询小类问题");
}
finally{
ConnectionFactory.close(con);
ConnectionFactory.close(ps);
ConnectionFactory.close(rs);
}
return content;
}
//根据商品的大类查询 所有商品
public List<TradeInformation> getTradsBySortId(int sortId)
{
List<TradeInformation> trads=new ArrayList<TradeInformation>();
TradeInformation shop=null;
try {
con=ConnectionFactory.getConnection();
ps=con.prepareStatement("select * from Trade_information where SortId1=? limit 10");
ps.setInt(1, sortId);
rs=ps.executeQuery();
while(rs.next())
{
shop=new TradeInformation(rs.getInt("id"),rs.getString("name"),rs.getString("shop_placeid"),
rs.getString("shere"),rs.getString("scope"),rs.getString("sortId1"),rs.getString("sortId2"),
rs.getDate("time1"),rs.getDate("time2"),rs.getDouble("price1"),rs.getDouble("price2"),rs.getDouble("price3"),
rs.getString("zhekou"),rs.getString("number"),rs.getString("size"),rs.getString("weight"),
rs.getString("url"),rs.getString("cuxiao"),rs.getString("baozhuang"),rs.getString("baozhiqi"),
rs.getString("Made_in"),rs.getString("shengchanshang"),rs.getString("zhuda"),
rs.getString("clicks"),rs.getString("cflag"),rs.getString("PictureScope"),rs.getString("PictureURlId"));
trads.add(shop);
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
ConnectionFactory.close(rs);
ConnectionFactory.close(ps);
ConnectionFactory.close(con);
}
return trads;
}
// 根据小类Tid获得小类的Father
public String getFatherByTid(int tid) {
String father = "";
try {
con = ConnectionFactory.getConnection();
ps = con.prepareStatement("select Father from Trade_sort where Tid=?");
ps.setInt(1, tid);
rs = ps.executeQuery();
while (rs.next()) {
father = rs.getString(1);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
ConnectionFactory.close(rs);
ConnectionFactory.close(ps);
ConnectionFactory.close(con);
}
return father;
}
public static void main(String[] args)
{
/*List<TradeInformation> list=new TradeSortDAO().getTradsBySortId(6);
System.out.println(list.size());
System.out.print(new TradeSortDAO().getSort2(201));*/
long lo=Long.parseLong("3539498000");
System.out.println(lo);
}
}
评论0