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

📄 carddao.java~14~

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


import com.jbaptech.accp.netbar.server.entity.Card;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 * <p>Title: com.jbaptech.accp.netbar.server.dao.CardDAO</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: 北京阿博泰克北大青鸟信息技术有限公司</p>
 *
 * @author luohao
 * @version 1.0
 */
public class CardDAO {
  public CardDAO() {
  }

  public boolean cardIsValid(Card card) {

    boolean cardIsValid = false;
    Connection dbConnection = null;
    PreparedStatement pStatement = null;
    ResultSet res = null;
    try {
      dbConnection = ConnectionManager.getConnction();
      // 查询数据SQL语句
      String strSql = "select * from card where id='" + card.getId()
          + "' and password ='" + card.getPassword() + "'";
      if (dbConnection != null) {
        System.out.println(dbConnection != null);
      }

      //查询操作
      pStatement = dbConnection.prepareStatement(strSql);
      res = pStatement.executeQuery();
      if (res.next()) {
        cardIsValid = true;
      }
    }catch (SQLException sqlE) {
      sqlE.printStackTrace();
    }
    finally {
      ConnectionManager.closeResultSet(res);
      ConnectionManager.closeStatement(pStatement);
      ConnectionManager.closeConnection(dbConnection);
    }

    return cardIsValid;
  }

  public boolean cardIsHaveBalance(Card card) {

   boolean haveBalance = false;
   Connection dbConnection = null;
   PreparedStatement pStatement = null;
   ResultSet res = null;
   try {
     dbConnection = ConnectionManager.getConnction();
     // 查询数据SQL语句
     String strSql = "select * from card where id='" + card.getId()
         + "' and password ='" + card.getPassword() + "'";
     if (dbConnection != null) {
       System.out.println(dbConnection != null);
     }

     //查询操作
     pStatement = dbConnection.prepareStatement(strSql);
     res = pStatement.executeQuery();
     if (res.next()) {
       int balance = res.getInt("balance");
       if(balance>=2)
       haveBalance = true;
     }
   }catch (SQLException sqlE) {
     sqlE.printStackTrace();
   }
   finally {
     ConnectionManager.closeResultSet(res);
     ConnectionManager.closeStatement(pStatement);
     ConnectionManager.closeConnection(dbConnection);
   }

   return haveBalance;
 }

}

⌨️ 快捷键说明

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