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

📄 linkdao.java~2~

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

import java.sql.*;
import java.util.*;

import com.tool.JDBConnection;
import com.tool.FinalConstants;
import com.domain.LinkForm;

//对友情连接网站表的操作
public class LinkDao {
  private Connection connection = null; //定义连接的对象
  private PreparedStatement ps = null; //定义预准备的对象
  private JDBConnection jdbc = null; //定义数据库连接对象
  public LinkDao() {
    jdbc = new JDBConnection();
    connection = jdbc.connection; //利用构造方法取得数据库连接
  }

  //删除的方法
  public void deleteLink(Integer id) {
    try {
      ps = connection.prepareStatement(FinalConstants.link_delete);
      ps.setInt(1, id.intValue());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    }
  }

  //修改的方法
  public void updateLink(LinkForm form) {
    try {
      ps = connection.prepareStatement(FinalConstants.link_update);
      ps.setString(1, form.getLinkName());
      ps.setString(2, form.getLinkAddress());
      ps.setInt(3, form.getId().intValue());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    }
  }

//添加的方法
  public void insertLink(LinkForm form) {
    try {
      ps = connection.prepareStatement(FinalConstants.link_insert);
      ps.setString(1, form.getLinkName());
      ps.setString(2, form.getLinkAddress());
      ps.setString(3, form.getLinkPicture());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    }
  }

  //以数据库流水号为条件查询的方法
  public LinkForm selectOneLink(Integer id) {
    LinkForm link = null;
    try {
      ps = connection.prepareStatement(FinalConstants.link_selectOne);
      ps.setInt(1, id.intValue());
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        link = new LinkForm();
        link.setId(Integer.valueOf(rs.getString(1)));
        link.setLinkName(rs.getString(2));
        link.setLinkAddress(rs.getString(3));
        link.setLinkPicture(rs.getString(4));
        link.setLinkTime(rs.getString(5));
      }
    }
    catch (SQLException ex) {
    }
    return link;
  }

//全部查询的方法
  public List selectLink() {
    List list = new ArrayList();
    LinkForm link = null;
    try {
      ps = connection.prepareStatement(FinalConstants.link_select);
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        link = new LinkForm();
        link.setId(Integer.valueOf(rs.getString(1)));
        link.setLinkName(rs.getString(2));
        link.setLinkAddress(rs.getString(3));
        link.setLinkPicture(rs.getString(4));
        link.setLinkTime(rs.getString(5));
        list.add(link);
      }
    }
    catch (SQLException ex) {
    }
    return list;
  }

}

⌨️ 快捷键说明

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