其他分享
首页 > 其他分享> > 简单的抽卡模拟器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();
    }
}

可以,这次出金了 

 

标签:stat,1.1,rs,private,String,抽卡,public,dbconn,模拟器
来源: https://blog.csdn.net/weixin_43462958/article/details/121132182