我正在使用这种方法:
public static boolean match(String name, String password) {
ResultSet result = null;
try {
result = World.database().executeQuery("SELECT password FROM " + PLAYER_TABLE + " WHERE username='" + name + "'");
if (result.next()) {
String passwordResult = result.getString("password");
String encryptedPassword = MD5Encryption.encrypt(password);
if (encryptedPassword.equals(passwordResult))
return true;
} else {
System.out.println("match(String name, String password: false.");
StringBuilder query = new StringBuilder();
query.append("INSERT INTO `frostblades_users` (id, username, displayName, previousname, lastChanged, password, email, reg_ip, reg_date, last_ip, last_online, picture, rights, playTime, forum, gender, donator, donatorTill, mute, muteTill, banned, online, sof_points, location, hitpoints, inventory_items, inventory_amount, equipment_items, equipment_amount, bank_items, bank_amount, bank_tabs, skills_level, skills_experience, looks, colours, points, friends, ignores, quest_points, music, prayer_points, pouch, run_energy, magic_book, prayer_book, familiar, bob_items, bob_amount, quest_states, quest_progress) VALUES(");
query.append("'" + player().definition().index() + "'").append(",");
query.append("'" + log.type().index() + "'").append(",");
query.append("'" + log.key() + "'").append(",");
query.append("'" + log.value() + "'").append(",");
query.append("'" + log.date() + "'").append(")");
World.database().executeUpdate(query.toString());
}
现在我以冒险日志为例:
StringBuilder query = new StringBuilder();
query.append("INSERT INTO `frostblades_adventurers_logs` (user_id, log_type, log_key, log_value, log_date) VALUES(");
query.append("'" + player().definition().index() + "'").append(",");
query.append("'" + log.type().index() + "'").append(",");
query.append("'" + log.key() + "'").append(",");
query.append("'" + log.value() + "'").append(",");
query.append("'" + log.date() + "'").append(")");
World.database().executeUpdate(query.toString());
我如何获得“player()。definition()。index()”这是为每个新帐户增加++的ID?
答案 0 :(得分:1)
要检查用户名是否存在,您可以执行如下查询:
SELECT Count(*) as numusers FROM users WHERE username = 'THEUSERNAME';
如果生成的numusers> 0然后用户名存在,否则不存在。因此,您需要使用查询构建器来创建和执行查询。
对于ID,最简单的方法是让数据库增加id,因此不要在数据库中插入id。