BookCaseDAO.java~42~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:3k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.dao;
  2. import com.core.ConnDB;
  3. import com.actionForm.BookCaseForm;
  4. import java.util.*;
  5. import java.sql.*;
  6. public class BookCaseDAO {
  7.     private ConnDB conn=new ConnDB();
  8.     //查询全部数据
  9.     public Collection query(String strif){
  10.         BookCaseForm bookCaseForm1=null;
  11.         Collection bookcaseColl=new ArrayList();
  12.         String sql="";
  13.         if(strif=="all" || strif==null){
  14.             sql="select * from tb_bookcase";
  15.         }else{
  16.             sql="select * from tb_bookcase where "+strif+"";
  17.         }
  18.         ResultSet rs=conn.executeQuery(sql);
  19.         try {
  20.             while (rs.next()) {
  21.                 bookCaseForm1=new BookCaseForm();
  22.                 bookCaseForm1.setId(Integer.valueOf(rs.getString(1)));
  23.                 bookCaseForm1.setName(rs.getString(2));
  24.                 bookcaseColl.add(bookCaseForm1);
  25.             }
  26.         } catch (SQLException ex) {
  27.         }
  28.         conn.close();
  29.         return bookcaseColl;
  30.     }
  31.     //带条件的查询
  32.     public Collection queryif(BookCaseForm bookCaseForm){
  33.         BookCaseForm bookCaseForm1=null;
  34.         Collection bookcaseColl=new ArrayList();
  35.         String sql="select * from tb_bookcase where id="+bookCaseForm.getId()+"";
  36.         ResultSet rs=conn.executeQuery(sql);
  37.         try {
  38.             while (rs.next()) {
  39.                 bookCaseForm1=new BookCaseForm();
  40.                 bookCaseForm1.setId(Integer.valueOf(rs.getString(1)));
  41.                 bookCaseForm1.setName(rs.getString(2));
  42.                 bookcaseColl.add(bookCaseForm1);
  43.             }
  44.         } catch (SQLException ex) {
  45.         }
  46.         conn.close();
  47.         return bookcaseColl;
  48.     }
  49.     //用于修改的查询
  50.     public BookCaseForm queryM(BookCaseForm bookCaseForm){
  51.         BookCaseForm bookCaseForm1=null;
  52.         String sql="select * from tb_bookcase where id="+bookCaseForm.getId()+"";
  53.         System.out.println("修改时的SQL:"+sql);
  54.         ResultSet rs=conn.executeQuery(sql);
  55.         try {
  56.             while (rs.next()) {
  57.                 bookCaseForm1=new BookCaseForm();
  58.                 bookCaseForm1.setId(Integer.valueOf(rs.getString(1)));
  59.                 bookCaseForm1.setName(rs.getString(2));
  60.             }
  61.         } catch (SQLException ex) {
  62.         }
  63.         conn.close();
  64.         return bookCaseForm1;
  65.     }
  66.    //添加数据
  67.     public int insert(BookCaseForm bookCaseForm){
  68.     String sql="Insert into tb_bookcase (name) values('"+bookCaseForm.getName()+"')";
  69.     int flag=conn.executeUpdate(sql);
  70.     conn.close();
  71.     return flag;
  72. }
  73.     //修改数据
  74.     public int update(BookCaseForm bookCaseForm){
  75.     String sql="Update tb_bookcase set name='"+bookCaseForm.getName()+"' where id="+bookCaseForm.getId()+"";
  76.     int falg=conn.executeUpdate(sql);
  77.     System.out.println("修改数据时的SQL:"+sql);
  78.     conn.close();
  79.     return falg;
  80. }
  81.     //删除数据
  82.     public int delete(BookCaseForm bookCaseForm){
  83.     String sql="Delete from tb_bookcase where id="+bookCaseForm.getId()+"";
  84.     int falg=conn.executeUpdate(sql);
  85.     System.out.println("删除时的SQL:"+sql);
  86.     return falg;
  87. }
  88. }