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

📄 carddao.java~26~

📁 我自己在做java训练的时候做的一个小项目
💻 JAVA~26~
字号:
package text;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author shanshan
 * @version 1.0
 */
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;
public class CardDAO {
    public CardDAO() {
    }
    public static int getBalance(Card card) {
    int  gBalance=0;
   Connection con = null;
   PreparedStatement pStatement = null;
   ResultSet res = null;
   try {
     con = JDBC_ODBC.getConnction();
     String strSql = "select * from card where id='" + card.getId()
         + "' and password ='" + card.getPassword() + "'";
     pStatement = con.prepareStatement(strSql);
     res = pStatement.executeQuery();
     if (res.next()) {
        gBalance=res.getInt(3);
     }
     System.out.println(gBalance);
   } catch (SQLException ce) {
     ce.printStackTrace();
   }
   return gBalance;
  }
   public  static boolean haveBalance(Card card) {
   boolean hBalance = false;
   Connection con = null;
   PreparedStatement pStatement = null;
   ResultSet res = null;
   try {
     con = JDBC_ODBC.getConnction();
     String strSql = "select * from card where id='" + card.getId()
         + "' and password ='" + card.getPassword() + "'";
     pStatement = con.prepareStatement(strSql);
     res = pStatement.executeQuery();
     if (res.next()) {
       int balance = res.getInt("balance");
       if (balance >= 2) {
         hBalance = true;
       }
     }
   } catch (SQLException sqlE) {
     sqlE.printStackTrace();
   }
   return hBalance;
  }


    public static  boolean isCard (Card card) {
        boolean isCard = false;
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet res = null;
        try {
            con = JDBC_ODBC.getConnction();
            String str = "select * from Card where Id='" + card.getId()
                            + "' and Password ='" + card.getPassword() + "'";
            pstmt = con.prepareStatement(str);
            res = pstmt.executeQuery();
            if (res.next()) {
                isCard = true;
            }
        } catch (SQLException ce) {
            ce.printStackTrace();
        }
        return isCard;
    }
    public static  boolean isUserCard(Card Usercard) {
        boolean isUserCard = false;
        Connection con = null;
        PreparedStatement pstmt = null;
        ResultSet res = null;
        try {
            con = JDBC_ODBC.getConnction();
            String str = "select * from Record where CardId='" + Usercard.getId()
                            + "' and EndTime is null";
            pstmt = con.prepareStatement(str);
            res = pstmt.executeQuery();
            if (res.next()) {
                isUserCard = true;
            }
        } catch (SQLException ce) {
            ce.printStackTrace();
        }
        return isUserCard;
    }
  }

⌨️ 快捷键说明

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