【发布时间】:2011-07-17 16:09:41
【问题描述】:
为游戏编写登录检查器,然后从 C# 切换到 java。问题是我使用较旧的代码作为示例,但通过从连接创建语句时不断遇到这个问题。我得到“未找到 createStatement() 符号”。是否有新的方法来执行 SQL 语句或有其他错误?
这里是源代码。
import java.sql.*;
public class SQLCheck {
public Connection con;
public void connect(){
String host = "somewhereoutthere";
String username = "stuff";
String pass = "haclmolg";
String db = "users";
try{
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://"+host+"/"+db+"?";
con = (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){
boolean correct = false;
Statement s = con.createStatement();
}
}
【问题讨论】:
-
附带说明,如果用户数量超过少数,请考虑转换为 OpenID,或至少使用安全协议对用户进行身份验证。
-
好的,一切都解决了。实际上,这两个答案都有帮助。是我忘记了“抛出 SQLException”
-
从我从 OpenID 用户那里读到的信息来看,您可能希望远离它。