开发者

Java-Compare data from textbox to sql record

开发者 https://www.devze.com 2023-02-17 17:56 出处:网络
Pretty much writing a launcher for a game and I need to take text from the Username text box, and a password textbox and then fetch the data from mysql server. This is what I have so far. Any help or

Pretty much writing a launcher for a game and I need to take text from the Username text box, and a password textbox and then fetch the data from mysql server. This is what I have so far. Any help or examples on how to do this?

public class SQLCheck {

    public java.sql.Connection con;
    public void connect(){
        String host = "sttfz";
        String username = "roiot";
        String pass = "yourmother";
        String db = "users";

        try{
            Class.forName("com.mysql.jdbc.Driver");
            Strin开发者_如何学Gog connectionUrl = "jdbc:mysql://"+host+"/"+db+"?";
            con = (java.sql.Connection) DriverManager.getConnection(connectionUrl,username,pass);
            System.out.println("Server: Connected to MYSQL");
        } catch(SQLException e){
            System.out.println("Server: SQL EXECEPTION: " + e.toString());
        } catch (ClassNotFoundException cE){
            System.out.println("Server: Class not found: " + cE.toString());
        }
    }
    boolean checkLogin(String userName, String password) throws SQLException{
        boolean correct = false;

        Statement s = con.createStatement();
        s.executeQuery("SELECT Username, Password, Banned, Activated FROM Users");
        ResultSet rs = s.getResultSet();

        return correct;
    }
}


Nearly there. Check out the official JDBC Tutorial and you'll realize what to do next in no time (hint: fetch the values from the resultset)

0

精彩评论

暂无评论...
验证码 换一张
取 消