package com.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.entity.BigClass;
import com.util.DBUtil;
public class BigClassDao {
/**
* 添加
* @param b_name
* @return k
*/
public static int add(String b_name){
String sql="insert into bigclass(b_name) values(?)";
Object obj[]={b_name};
int k=DBUtil.Update(sql, obj);
return k;
}
/**
* 根据编号修改分类名称
* @param b_name
* @param b_id
* @return
*/
public static int update(String b_name,String b_id){
String sql="update bigclass set b_name=? where b_id=?";
Object obj[]={b_name,b_id};
int k=DBUtil.Update(sql, obj);
return k;
}
/**
* 根据编号删除大分类信息
* @param b_id
* @return
*/
public static int delete(String b_id){
String sql="delete from bigclass where b_id=?";
Object obj[]={b_id};
int k=DBUtil.Update(sql, obj);
return k;
}
/**
* 判断输入的分类名称是否已存在
* @param bname
* @return boolean
*/
public static boolean getBname(String bname){
String sql="select * from bigClass where b_name=?";
Object obj[]={bname};
ResultSet res=DBUtil.query(sql, obj);
try {
if (res.next()) {
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.close();
}
return false;
}
/**
* 查询分类总条数
* @return count
*/
public static int bigClassCount(){
int count=0;
String sql="select count(*) from bigClass";
Object obj[]={};
ResultSet res=DBUtil.query(sql, obj);
try {
if (res.next()) {
count=res.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.close();
}
return count;
}
/**
* 查询所有大分类信息 分页查询
* @return list集合
*/
public static List queryAll(Integer pageStart,Integer pageSize){
String sql="select * from bigClass limit ?,?";
Object obj[]={pageStart,pageSize};
ResultSet res=DBUtil.query(sql, obj);
List list=new ArrayList();
try {
while(res.next()){
BigClass bi=newBigClass(res.getInt(1), res.getString(2));
list.add(bi);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.close();
}
return list;
}
/**
* 查询所有大分类信息
* @return list集合
*/
public static List queryAll(){
String sql="select * from bigClass";
Object obj[]={};
ResultSet res=DBUtil.query(sql, obj);
List list=new ArrayList();
try {
while(res.next()){
BigClass bi=newBigClass(res.getInt(1), res.getString(2));
list.add(bi);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.close();
}
return list;
}
/**
* 根据名称查询大分类编号
* @return b_id
*/
public static String queryId(String b_name){
String sql="select b_id from bigClass where b_name=?";
Object obj[]={b_name};
ResultSet res=DBUtil.query(sql, obj);
String b_id=null;
try {
if(res.next()){
b_id=res.getString(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.close();
}
return b_id;
}
/**
* 根据编号查询大分类名称
* @return b_name
*/
public static String queryName(String b_id){
String sql="select b_name from bigClass where b_id=?";
Object obj[]={b_id};
ResultSet res=DBUtil.query(sql, obj);
String b_name=null;
try {
if(res.next()){
b_name=res.getString(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtil.close();
}
return b_name;
}
}