⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productsortdao.java

📁 仓库管理系统,适合各种行业的仓库管理系统
💻 JAVA
字号:
package com.bean.DAO;


import java.sql.*;
import java.util.ArrayList;
import java.util.List;



import com.bean.DTO.ProductsortDTO;


public class ProductsortDAO {
private final String sql_getall="select * from productsort";
private final String sql_add="insert into productsort values(?,?)";
private final String sql_del="delete from productsort where sortID=?";
private final String sql_getname="select name from productsort where sortID=?";
private final String sql_update="update productsort set name=?,information=? where sortID=?";
private List<ProductsortDTO> plist;
public ProductsortDAO(){
	plist=new ArrayList<ProductsortDTO>();
}
public List<ProductsortDTO> getAll(Connection con){
	try {
		PreparedStatement ps=con.prepareStatement(this.sql_getall);
		ResultSet rs=ps.executeQuery();
		while(rs.next()){
			ProductsortDTO pd=new ProductsortDTO();
			pd.setSortID(rs.getInt(1));
			pd.setName(rs.getString(2));
			pd.setInformation(rs.getString(3));
			plist.add(pd);
		}		
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return plist;
}
public ProductsortDTO getProductsortDTO(int sortID,Connection con){
	ProductsortDTO psd=new ProductsortDTO();
	try {
		PreparedStatement ps=con.prepareStatement("select * from productsort where sortID=?");
		ps.setInt(1, sortID);
		ResultSet rs=ps.executeQuery();
		while(rs.next()){
			psd.setSortID(sortID);
			psd.setName(rs.getString(2));
			psd.setInformation(rs.getString(3));
		}		
		ps.execute();
		
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return psd;
}
public boolean Addproductsort(ProductsortDTO pd,Connection con){
	try {
		PreparedStatement ps=con.prepareStatement(this.sql_add);
		ps.setString(1,pd.getName());
		ps.setString(2,pd.getInformation());	
		ps.execute();
		
		return true;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return false;
}
public boolean Delproductsort(int productID,Connection con){
	try {
		PreparedStatement ps=con.prepareStatement(this.sql_del);
		ps.setInt(1,productID);
		ps.execute();
		
		return true;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return false;
}
public boolean updproductsort(ProductsortDTO pd,Connection con){
	try {
		PreparedStatement ps=con.prepareStatement(sql_update);
		
		ps.setInt(3,pd.getSortID());
		ps.setString(1,pd.getName());
		ps.setString(2,pd.getInformation());		
		ps.execute();
		
		return true;
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return false;
}
public String getSortname(int id,Connection con){
	String name=null;
	try {
		PreparedStatement ps=con.prepareStatement(this.sql_getname);
		ps.setInt(1, id);
		ResultSet rs = ps.executeQuery();
		if(rs.next()){
			name=rs.getString(1);
			return name;
		}
		
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return "无分类";
}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -