computerdao.java~9~

来自「ACCP课程中的商业程序网吧管理系统」· JAVA~9~ 代码 · 共 62 行

JAVA~9~
62
字号
package com.jbaptech.accp.netbar.server.dao;

import com.jbaptech.accp.netbar.server.entity.Card;
import java.sql.*;
import java.util.ArrayList;
import com.jbaptech.accp.netbar.server.entity.Computer;

public class ComputerDAO extends BaseDAO{
  public ComputerDAO(){
  }

  public ArrayList getNoUsedComputerList() {

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

     //查询操作
     this.pStatement = this.dbConnection.prepareStatement(this.strSql);
     this.res = this.pStatement.executeQuery();
     while (this.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 {
       this.clearDao();
   } //finally

   return list;
 }

 public void recordOnUse(Computer computer) {
   try {
     this.strSql =
         "update computer set OnUse =1 where id =(?) ; ";

     this.pStatement = this.dbConnection.prepareStatement(this.strSql);
     this.pStatement.setString(1, computer.getId());
     this.pStatement.executeUpdate();
   }
   catch (SQLException sqlE) {
     sqlE.printStackTrace();
   }
   finally {
     this.clearDao();
   } //finally
 }

}

⌨️ 快捷键说明

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