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

📄 smalltypedao.java~3~

📁 这是一个用Struts做出来的网上商城的源代码
💻 JAVA~3~
字号:
package com.dao;

import com.tool.JDBConnection;
import com.tool.FinalConstants;
import java.sql.*;
import java.util.*;
import com.domain.SmallTypeForm;

//对商品小类别信息的操作
public class SmallTypeDao {
  private Connection connection = null; //定义连接的对象
  private PreparedStatement ps = null; //定义预准备的对象
  private JDBConnection jdbc = null; //定义数据库连接对象
  public SmallTypeDao() {
    jdbc = new JDBConnection();
    connection = jdbc.connection; //利用构造方法取得数据库连接
  }
//以小类别外关键为条件查询信息
  public List selectOneBigId(Integer bigId) {
   List list=new ArrayList();
    SmallTypeForm small = null;
      try {
        this.ps = connection.prepareStatement(FinalConstants.small_selectBigId);
        ps.setString(1, bigId.toString());
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
          small = new SmallTypeForm();
          small.setId(Integer.valueOf(rs.getString(1)));
          small.setBigId(Integer.valueOf(rs.getString(2)));
          small.setSmallName(rs.getString(3));
          small.setCreaTime(rs.getString(4));
          list.add(small);
        }
      }
      catch (SQLException ex) {
      }
      return list;
    }



//以数据库流水号为条件查询小类别的名称
  public String selectName(Integer id) {
    String name = null;
    try {
      this.ps = connection.prepareStatement(FinalConstants.small_selectOne);
      ps.setString(1, id.toString());
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        name = rs.getString("smallName");
      }
    }
    catch (SQLException ex) {
    }
    return name;
  }

//删除操作
  public void deleteSmall(Integer id) {
    try {
      ps = connection.prepareStatement(FinalConstants.small_delete);
      ps.setString(1, id.toString());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    }
  }

  //修改操作
  public void updateSmall(SmallTypeForm form) {
    try {
      ps = connection.prepareStatement(FinalConstants.small_update);
      ps.setString(1,form.getBigId().toString());
      ps.setString(2, form.getSmallName());
      ps.setString(3, form.getId().toString());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    }
  }

  //添加操作
  public void insertSmall(SmallTypeForm form) {
    try {
      ps = connection.prepareStatement(FinalConstants.small_insert);
      ps.setString(1,form.getBigId().toString());
      ps.setString(2, form.getSmallName());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    }
  }

  //以数据库流水号为条件查询信息
  public SmallTypeForm selectOneBig(Integer id) {
    SmallTypeForm small = null;
    try {
      this.ps = connection.prepareStatement(FinalConstants.small_selectOne);
      ps.setString(1, id.toString());
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        small = new SmallTypeForm();
        small.setId(Integer.valueOf(rs.getString(1)));
        small.setBigId(Integer.valueOf(rs.getString(2)));
        small.setSmallName(rs.getString(3));
        small.setCreaTime(rs.getString(4));
      }
    }
    catch (SQLException ex) {
    }
    return small;
  }

  //全部查询的操作
  public List selectSmall() {
    List list = new ArrayList();
    SmallTypeForm small = null;
    try {
      this.ps = connection.prepareStatement(FinalConstants.small_select);
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        small = new SmallTypeForm();
        small.setId(Integer.valueOf(rs.getString(1)));
        small.setBigId(Integer.valueOf(rs.getString(2)));
        small.setSmallName(rs.getString(3));
        small.setCreaTime(rs.getString(4));
        list.add(small);
      }
    }
    catch (SQLException ex) {
    }
    return list;
  }
}

⌨️ 快捷键说明

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