Java将文本框中的数据与sql记录进行比较
基本上是为游戏编写一个启动器,我需要从用户名文本框和密码文本框中获取文本,然后从mysql服务器获取数据。这就是我目前所拥有的。有关于如何做到这一点的帮助或示例吗Java将文本框中的数据与sql记录进行比较,java,mysql,sql,select,Java,Mysql,Sql,Select,基本上是为游戏编写一个启动器,我需要从用户名文本框和密码文本框中获取文本,然后从mysql服务器获取数据。这就是我目前所拥有的。有关于如何做到这一点的帮助或示例吗 public class SQLCheck { public java.sql.Connection con; public void connect(){ String host = "sttfz"; String username = "roiot"; String
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");
String 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;
}
}
快到了。查看官方网站,您很快就会意识到下一步要做什么(提示:从resultset获取值)