BookCaseDAO.java~43~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:3k
- package com.dao;
- import com.core.ConnDB;
- import com.actionForm.BookCaseForm;
- import java.util.*;
- import java.sql.*;
- public class BookCaseDAO {
- private ConnDB conn=new ConnDB();
- //查询全部数据
- public Collection query(String strif){
- BookCaseForm bookCaseForm1=null;
- Collection bookcaseColl=new ArrayList();
- String sql="";
- if(strif=="all" || strif==null || strif==""){
- sql="select * from tb_bookcase";
- }else{
- sql="select * from tb_bookcase where "+strif+"";
- }
- ResultSet rs=conn.executeQuery(sql);
- try {
- while (rs.next()) {
- bookCaseForm1=new BookCaseForm();
- bookCaseForm1.setId(Integer.valueOf(rs.getString(1)));
- bookCaseForm1.setName(rs.getString(2));
- bookcaseColl.add(bookCaseForm1);
- }
- } catch (SQLException ex) {
- }
- conn.close();
- return bookcaseColl;
- }
- //带条件的查询
- public Collection queryif(BookCaseForm bookCaseForm){
- BookCaseForm bookCaseForm1=null;
- Collection bookcaseColl=new ArrayList();
- String sql="select * from tb_bookcase where id="+bookCaseForm.getId()+"";
- ResultSet rs=conn.executeQuery(sql);
- try {
- while (rs.next()) {
- bookCaseForm1=new BookCaseForm();
- bookCaseForm1.setId(Integer.valueOf(rs.getString(1)));
- bookCaseForm1.setName(rs.getString(2));
- bookcaseColl.add(bookCaseForm1);
- }
- } catch (SQLException ex) {
- }
- conn.close();
- return bookcaseColl;
- }
- //用于修改的查询
- public BookCaseForm queryM(BookCaseForm bookCaseForm){
- BookCaseForm bookCaseForm1=null;
- String sql="select * from tb_bookcase where id="+bookCaseForm.getId()+"";
- System.out.println("修改时的SQL:"+sql);
- ResultSet rs=conn.executeQuery(sql);
- try {
- while (rs.next()) {
- bookCaseForm1=new BookCaseForm();
- bookCaseForm1.setId(Integer.valueOf(rs.getString(1)));
- bookCaseForm1.setName(rs.getString(2));
- }
- } catch (SQLException ex) {
- }
- conn.close();
- return bookCaseForm1;
- }
- //添加数据
- public int insert(BookCaseForm bookCaseForm){
- String sql="Insert into tb_bookcase (name) values('"+bookCaseForm.getName()+"')";
- int flag=conn.executeUpdate(sql);
- conn.close();
- return flag;
- }
- //修改数据
- public int update(BookCaseForm bookCaseForm){
- String sql="Update tb_bookcase set name='"+bookCaseForm.getName()+"' where id="+bookCaseForm.getId()+"";
- int falg=conn.executeUpdate(sql);
- System.out.println("修改数据时的SQL:"+sql);
- conn.close();
- return falg;
- }
- //删除数据
- public int delete(BookCaseForm bookCaseForm){
- String sql="Delete from tb_bookcase where id="+bookCaseForm.getId()+"";
- int falg=conn.executeUpdate(sql);
- System.out.println("删除时的SQL:"+sql);
- return falg;
- }
- }