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

📄 computerdao.java~13~

📁 网吧计费系统 通过程序实现网吧计费系统的过程
💻 JAVA~13~
字号:
package com.jbaptech.accp.netbar.server.dao;

import java.util.ArrayList;
import com.jbaptech.accp.netbar.server.entity.Computer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * class descrition here.
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: 北京阿博泰克北大青鸟信息技术有限公司</p>
 *
 * @author luohao
 * @version 1.0
 */
public class ComputerDAO {
  /**
   * constructor.
   */
  public ComputerDAO() {
  }

  /**
   *  get not used computer list.
   * @return ArrayList
   */
  public final ArrayList getNoUsedComputerList() {

    ArrayList list = new ArrayList();
    Connection dbConnection = null;
    PreparedStatement pStatement = null;
    ResultSet res = null;

    try {
      dbConnection = ConnectionManager.getConnction();
      // 查询数据SQL语句
      String strSql = "select * from computer where onuse!= '1'";
      if (dbConnection != null) {
        System.out.println(dbConnection != null);
      }

      //查询操作
      pStatement = dbConnection.prepareStatement(strSql);
      res = pStatement.executeQuery();
      while (res.next()) {
        Computer computer = new Computer();
        computer.setId(res.getString("id"));
        computer.setOnUse(res.getString("onuse"));
        computer.setNotes(res.getString("notes"));
        list.add(computer);
      }
    } catch (SQLException sqlE) {
      sqlE.printStackTrace();
    } finally {
      ConnectionManager.closeResultSet(res);
      ConnectionManager.closeStatement(pStatement);
      ConnectionManager.closeConnection(dbConnection);

    } //finally

    return list;
  }

  /**
   * record the computer have used.
   * @param computer Computer
   */
  public final void recordOnUse(final Computer computer) {
    Connection dbConnection = null;
    PreparedStatement pStatement = null;
    try {
      String strSql =
          "update computer set OnUse =1 where id =(?) ; ";

      pStatement = dbConnection.prepareStatement(strSql);
      pStatement.setString(1, computer.getId());
      pStatement.executeUpdate();
    } catch (SQLException sqlE) {
      sqlE.printStackTrace();
    } finally {
      ConnectionManager.closeStatement(pStatement);
      ConnectionManager.closeConnection(dbConnection);
    }
  }
}

⌨️ 快捷键说明

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