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