📄 productmanager.java~13~
字号:
package zhaobiao.db;
import java.util.*;
import java.sql.*;
import zhaobiao.db.*;
import zhaobiao.data.*;
/**
* <p>Title: 产品信息管理类</p>
* <p>Description: 有关产品的浏览操作</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class ProductManager {
public ProductManager() {
}
/** 获得所有的类别集合
*
*
*/
public Vector getTypeList()
{
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from type";
try {
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
Type type=new Type();
type.setType_id(rs.getLong("type_id"));
type.setType_name(rs.getString("type_name"));
type.setType_content(rs.getString("type_content"));
list.add(type);
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return list;
}
/** 获得类别下的所有产品集合
*
*
*/
public Vector getProductList(long page ,long pagemax,long type_id)
{
page=page-1;
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from product where type_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,type_id) ;
rs=ps.executeQuery();
int count=1;
while(rs.next())
{
if (count>(page*pagemax)&&count<=(page*pagemax+pagemax)){
Product pd=new Product();
pd.setProduct_id(rs.getLong("product_id"));
pd.setProduct_name(rs.getString("product_name"));
pd.setType_id(rs.getLong("type_id"));
pd.setProduct_content("product_content");
list.add(pd);
}
count++;
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return list;
}
/** 获得类别下的所有产品集合的数目
*
*
*/
public long getProductListCount(long type_id)
{
long count=0;
Vector list=new Vector();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from product where type_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,type_id) ;
rs=ps.executeQuery();
while(rs.next())
{
count++;
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
freeCon();
return count;
}
/** 根据该产品id获得PPM表中的项目集合(去掉PPM表中重复的project_id)
*
*
*/
public Set getProjectList(long page ,long pagemax,long product_id)
{
page=page-1;
Set set1=new TreeSet();
Set set2=new TreeSet();
Basic basic=new Basic();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from ppm where product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,product_id);
rs=ps.executeQuery();
int count=1;
while(rs.next())
{
long projectid;
Project pj=new Project();
projectid=rs.getLong("project_id");
pj=basic.getProject(projectid);
if(set1.add(pj))
{
if (count>(page*pagemax)&&count<=(page*pagemax+pagemax))
{
set2.add(pj);;
}
count++; //计数器加1
}
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
basic.freeCon();
freeCon();
return set2;
}
/** 根据该产品id获得PPM表中的项目集合数量(去掉PPM表中重复的project_id)
*
*
*/
public long getProjectListCount(long product_id)
{
Set set1=new TreeSet();
long count=0;
Basic basic=new Basic();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from ppm where product_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,product_id);
rs=ps.executeQuery();
while(rs.next())
{
long projectid;
Project pj=new Project();
projectid=rs.getLong("project_id");
pj=basic.getProject(projectid);
if(set1.add(pj))
{
count++; //计数器加1
}
}
}
catch (SQLException ex) {
freeCon();
ex.printStackTrace();
}
basic.freeCon();
freeCon();
return count;
}
public Vector getProductMakerid(long maker_id)
{
Basic basic=new Basic();
Vector list=new Vector();
Product pd=new Product();
db=DBConnectionManager.getInstance();
con=db.getConnection("idb");
String sql="select *from product where maker_id=?";
try {
ps=con.prepareStatement(sql);
ps.setLong(1,maker_id);
rs=ps.executeQuery();
while(rs.next())
{
pd.setProduct_id(rs.getLong("product_id"));
pd.setProduct_name(rs.getString("product_name"));
pd.setType_id(rs.getLong("type_id"));
pd.setProduct_content(rs.getString("product_content"));
pd.setMaker_id(rs.getLong("maker_id"));
list.add(pd);
}
}
catch (SQLException ex) {
ex.printStackTrace();
}
freeCon();
return list;
}
/**
* 释放数据库资源<p>
*PreparedStatement和ResultSep将关闭,Connection返回给连接池
* @param 无
* @repurn 无
* @exception SQLException
*
*/
public void freeCon(){
try {
if (rs!=null)
rs.close() ;
if (ps!=null)
ps.close() ;
}
catch (SQLException ex) {
}
if (db!=null)
db.freeConnection("idb",con) ;
}
public static void main(String[] args) {
ProductManager productManager1 = new ProductManager();
}
private DBConnectionManager db;
private Connection con=null;
private ResultSet rs=null;
private PreparedStatement ps=null;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -