简单的抽卡模拟器1.1

简单的抽卡模拟器1.1

 

连接了数据库

import java.sql.Connection;
import java.sql.DriverManager;

public class dataBase {
    private String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //驱动
    private String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=testJava";// 端口 数据库名
    private String userName="kyvlms";
    private String userPwd="19990616op";

    Connection connect () throws Exception{
        Class.forName(driverName);
        Connection dbConn = DriverManager.getConnection(dbURL,userName,userPwd);
        return  dbConn;
    }
}

存卡片段 

public class Cardsql {
    private List<String> blueCard = new ArrayList<>();
    private List<String> purpleCard = new ArrayList<>();
    private List<String> goldCard = new ArrayList<>();

    public Cardsql() throws Exception {
        setBlueCard();
        setGoldCard();
        setPurpleCard();
    }

    public List<String> getBlueCard() {
        return blueCard;
    }

    public void setBlueCard() throws Exception {
        Connection dbconn = new dataBase().connect();
        Statement stat = dbconn.createStatement();
        String a = "SELECT * FROM blueCard ORDER BY Card_Name ";
        ResultSet rs = stat.executeQuery(a);
        while(rs.next()){
            blueCard.add(rs.getString("Card_Name"));
        }
        dbconn.close();
    }

    public List<String> getPurpleCard() {
        return purpleCard;
    }

    public void setPurpleCard() throws Exception {
        Connection dbconn = new dataBase().connect();
        Statement stat = dbconn.createStatement();
        String a = "SELECT * FROM purpleCard ORDER BY Card_Name ";
        ResultSet rs = stat.executeQuery(a);
        while(rs.next()){
            purpleCard.add(rs.getString("Card_Name"));
        }
        dbconn.close();
    }

    public List<String> getGoldCard() {
        return goldCard;
    }

    public void setGoldCard() throws Exception {
        Connection dbconn = new dataBase().connect();
        Statement stat = dbconn.createStatement();
        String a = "SELECT * FROM goldCard ORDER BY Card_Name ";
        ResultSet rs = stat.executeQuery(a);
        while(rs.next()){
            goldCard.add(rs.getString("Card_Name"));
        }
        dbconn.close();
    }
}

可以,这次出金了 

简单的抽卡模拟器1.1

 

上一篇:The Rust Programming Language - 第11章 测试 - 11.3 测试的组织结构


下一篇:JDBC通用的查询数据库方法