placedao.java

来自「图书管理系统。JSP+Struts(MVC框架)sql2000数据库」· Java 代码 · 共 173 行

JAVA
173
字号
package com.dao;

import java.sql.*;
import org.apache.xml.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import com.tool.JDBCConnection;
import com.actionForm.PlaceForm;
import com.tool.DealwithString;
import java.util.ArrayList;

public class PlaceDao {
    private JDBCConnection con=null;

    public PlaceDao(){
     con=new JDBCConnection();
     this.con.createConnection();
    }
/********************添加书架**********************************************************/

  public boolean insertPlace(PlaceForm bookForm) {
      try{
          String sql = "insert into tb_bookPlace values('"+bookForm.getPlaceNumber() + "','" +
                       bookForm.getPlaceName() + "')";
          con.executeQuery(sql);
          con.closeConneciton();
          return true;
      }catch(Exception e){
      return false;
      }

   }
/******************删除书架************************************************************/

   public boolean deletePlace(PlaceForm bookForm){

       String sql="delete from tb_bookPlace where placeName='"+bookForm.getPlaceName()+"'";
       con.executeUpdata(sql);
       con.closeConneciton();
      return true;
    }
/*********************** 修改*******************************************************/

    public boolean updatePlace(PlaceForm tmForm){
        try{
            String sql = "update tb_bookPlace set placeNumber='" +
                         tmForm.getPlaceNumber() + "' where placeName='" +
                         tmForm.getPlaceName() + "'";
            con.executeUpdata(sql);
            con.closeConneciton();
            return true;
        }catch(Exception e){
        return false;
        }
  }
/*********************自动编号的方法*********************************************************/

 public String selectMaxIdPlace() {
     List list=new ArrayList();
    String place = null;
    PlaceForm form = null;
    String sql="select * from tb_bookPlace where id=(select Max(id) from tb_bookPlace)";
    ResultSet rs=con.executeQuery(sql);
    try {
               while (rs.next()) {
                   form = new PlaceForm();
                   form.setId(new Integer(rs.getInt("id")));
                   form.setPlaceNumber(rs.getString("PlaceNumber"));
                   form.setPlaceName(rs.getString("placeName"));
                   list.add(form);
               }
           } catch (SQLException ex) {}
    if (form != null) {
        place = form.getPlaceNumber();
    }
    place = DealwithString.maxNumberString(place, "P-", 2);
    con.closeConneciton();
    return place;
  }
/*******************查询****************************************************/
  //条件查询
  public PlaceForm selectPlace(PlaceForm form) {
      System.out.println("正在查询中1234...........");
      String sql = "select * from tb_bookPlace where placeName='"+form.getPlaceName()+"'order by id";
      ResultSet rs = con.executeQuery(sql);
      try {
          while (rs.next()) {
             form = new PlaceForm();
             form.setId(Integer.valueOf(rs.getString("id")));
             form.setPlaceNumber(rs.getString("placeNumber"));
             form.setPlaceName(rs.getString("placeName"));
          }
      } catch (SQLException ex) {
          System.out.println("错误4..........");
      }
      con.closeConneciton();
      return form;
 }

//全部查询分页显示
       public List selectPlace() {
        System.out.println("正在查询中123...........");
        List list = new ArrayList();
        PlaceForm tmForm=null;
        String sql="select * from tb_bookPlace order by id";
        ResultSet rs=con.executeQuery(sql);
        try {
          while (rs.next()) {
              tmForm = new PlaceForm();
              tmForm.setId(Integer.valueOf(rs.getString("id")));
              tmForm.setPlaceNumber(rs.getString("placeNumber"));
              tmForm.setPlaceName(rs.getString("placeName"));
              list.add(tmForm);
          }
       } catch (Exception ex) {
     System.out.println("错误1..........");
         }
      con.closeConneciton();
      return list;
   }

//全部查询
/*public List selectPlace() {
  System.out.println("正在查询中1...........");
   List list = new ArrayList();
   PlaceForm tmForm=null;
   String sql="select * from tb_bookPlace";
   ResultSet rs=con.executeQuery(sql);
   try {
       while (rs.next()) {
                tmForm = new PlaceForm();
                tmForm.setId(Integer.valueOf(rs.getString("id")));
                tmForm.setPlaceName(rs.getString("placeName"));
                tmForm.setPlaceNumber(rs.getString("PlaceNumber"));
                list.add(tmForm);
            }
   } catch (Exception ex) {
   System.out.println("错误2..........");
   }
   con.closeConneciton();
   return list;
}*/
//查询出多少条纪录
/*public int selectPlace(){
  System.out.println("正在查询中12...........");
 List list = new ArrayList();
 PlaceForm bookForm=null;
 String sql=("select * from tb_bookPlace order by id");
 ResultSet rs=con.executeQuery(sql);
  try{
      while (rs.next()) {
            bookForm = new PlaceForm();
            bookForm.setId(Integer.valueOf(rs.getString("id")));
            bookForm.setPlaceNumber(rs.getString("PlaceNumber"));
            bookForm.setPlaceName(rs.getString("placeName"));
            list.add(bookForm);
        }
  }catch(Exception e){
  System.out.println("错误3..........");
  }
  int number=list.size();
  if (number % 13 == 0) {
      number = number / 13;
  } else {
      number = number / 13 + 1;
  }
 con.closeConneciton();
 return number;
}*/

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?