Java-比较文本框中的数据和sql记录
几乎为游戏编写了一个启动器,我需要从用户名文本框和密码文本框中获取文本,然后从 mysql 服务器获取数据。这是我到目前为止所拥有的。有关如何执行此操作的任何帮助或示例?
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;
}
}
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");
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快到了。查看官方 JDBC 教程,您就会知道下一步该做什么立即(提示:从结果集中获取值)
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)