⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitdao.java

📁 功能描述::::jsp实现的销售管理系统
💻 JAVA
字号:
package com.dao;

import com.tool.JDBConnection;
import java.util.*;
import com.domain.UnitVO;
import java.sql.*;

//对计量单位的操作
public class UnitDao {
  private JDBConnection connection = null;
  public UnitDao() {
    connection = new JDBConnection();
    this.connection.creatConnection(); //利用构造方法调用类中的对象对数据库创建连接
  }

  //查询全部的计量单位
  public List unitSelect() {
    List list = new ArrayList();
    UnitVO unit = null;
    String sql = "select * from tb_unit order by id";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        unit = new UnitVO();
        unit.setId(Integer.valueOf(rs.getString(1)));
        unit.setUnit_number(rs.getString(2));
        unit.setUnit_name(rs.getString(3));
        unit.setUnit_remark(rs.getString(4));
        list.add(unit);
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return list;
  }

//以员工编号为条件查询信息
  public UnitVO unitSelectOne(String number) {
    UnitVO unit = null;
    String sql = "select * from tb_unit where unit_number='" + number + "'";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        unit = new UnitVO();
        unit.setId(Integer.valueOf(rs.getString(1)));
        unit.setUnit_number(rs.getString(2));
        unit.setUnit_name(rs.getString(3));
        unit.setUnit_remark(rs.getString(4));
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return unit;
  }

//以名称为条件查询
  public UnitVO unitSelectName(String name) {
    UnitVO unit = null;
    String sql = "select * from tb_unit where unit_name='" + name + "'";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        unit = new UnitVO();
        unit.setId(Integer.valueOf(rs.getString(1)));
        unit.setUnit_number(rs.getString(2));
        unit.setUnit_name(rs.getString(3));
        unit.setUnit_remark(rs.getString(4));
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return unit;
  }

//添加操作
  public void unitInsert(UnitVO vo) {
    String sql = "insert into tb_unit values ('" + vo.getUnit_number() + "','" +
        vo.getUnit_name() + "','" + vo.getUnit_remark() + "')";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  //删除操作
  public void unitDelete(Integer id) {
    String sql = "delete from tb_unit where id='" + id + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  //修改编号的操作
  public void unitUpdateNumber(Integer id, String number) {
    String unNumber = "unit-" + String.valueOf(id);
    String sql = "update tb_unit set unit_number='" + unNumber +
        "'  where unit_number='" + number + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  //修改操作
  public void unitUpdate(UnitVO vo) {
    String sql = "update tb_unit set unit_name='" + vo.getUnit_name() +
        "',unit_remark='" + vo.getUnit_remark() + "' where unit_number='" +
        vo.getUnit_number() + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }
}

⌨️ 快捷键说明

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