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