Java教程

简单的抽卡模拟器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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!