我想将我的 Vote4Cash 类与我的命令类合并。
我的 vote4cash 课程将在玩家输入命令检查时奖励他们的投票。因此,我需要将 vote4cash 进程构建到我的命令类中。我一直在尝试这样做,这是我的 vote4cash 系统中最重要的部分。如果您知道我如何将它们合并在一起或使它们一起工作,请告诉我如何。我尝试使用导入,但没有成功。我没有编写命令类,其他人编写了代码,这让我更难添加 vote4gold 进程或让它们一起工作。
我的 Vote4Cash 课程:
import java.sql.*;
import java.net.*;
public class Vote4Cash {
public static void main(String args[]) {
Connection con = null;
Statement st = null;
Statement stmt = null;
ResultSet auth = null;
ResultSet given = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "vote4gold";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "";
try {
Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
con.setAutoCommit(false);
st = con.createStatement();
stmt = con.createStatement();
//String give = "SELECT `given` FROM `has_voted` WHERE `ip` LIKE '+thisIp.getHostAddress()'";
InetAddress thisIp =InetAddress.getLocalHost();
String give = "SELECT `given` FROM `has_voted` " +
"WHERE `ip` = '" + thisIp.getHostAddress() + "'";
given = st.executeQuery(give);
while (given.next()) {
if (given.getInt("given") > 0) {
System.out.println("You've already recieved a reward for the last time you voted, but thanks again for voting.");
} else {
System.out.println("Thanks for voting! You've been rewarded 25m gold! Vote again tomorrow!");
String sql = "SELECT has_voted (given) Replace('0', '0', '1')";
int rows = stmt.executeUpdate("UPDATE has_voted SET given = 1 WHERE given = 0");
System.out.println("The given reward column has been set to 1 for the ip address:");
System.out.println("IP:"+thisIp.getHostAddress());
}
}
} catch (Exception e) {
System.out.println(e);
}
}
}
我的命令类(不适合这里): http: //pastebin.com/GXFLfMX4
谢谢!如果您需要更多详细信息或不明白某些内容,请告诉我,以便我帮助您。:)