0
這是我的世界的插件。它應該拉動配置中設置的客戶ID並將它們展示給玩家。它反而會吸引每個人,不管他們的客戶ID是什麼。SQL查詢正在拉一切?
if(cmd.getName().equalsIgnoreCase("getaward"))
{
Player player = (Player)sender;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection (dbUrl,dbUser,dbPass);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM `votesdb` WHERE `nick` = '"+player.getName().substring(0,player.getName().length()/2)+"' AND `customer_id` LIKE "+config.getString("customer_id")+"");
//ResultSet rs = stmt.executeQuery("SELECT nick,votes FROM `votesdb` WHERE nick='"+player.getName()+" LIMIT 1");
if(rs.next())
{
if(rs.getInt("votes")!=0)
{
player.sendMessage(ChatColor.GREEN+"[VFD]"+ChatColor.AQUA+"Thanks for voting! You will find something special in your inventory. :)");
bukkit.broadcastMessage(ChatColor.GREEN+"[VFD]"+ChatColor.AQUA+player.getDisplayName()+" has been rewarded for Voting for the Server!");
stmt.executeUpdate("UPDATE `votesdb` SET flag=0 WHERE `nick` LIKE '"+player.getDisplayName().substring(0,player.getDisplayName().length()/2)+"'");
player.getInventory().addItem(new ItemStack(this.matID,this.matAmt));
}
else
{
player.sendMessage(ChatColor.RED+"You have already claimed your reward.");
}
}
else
{
player.sendMessage(ChatColor.RED+"We could not find you in the database! Please make sure you used the correct name when you voted!");
}
如果客戶Id是唯一的,那麼你不使用equals('customer_id' = config.getString(「customer_id」))而不是像...... – Shehzad 2012-04-14 10:12:52
是我的問題嗎?我需要使用=而不是像? – 2012-04-14 10:27:05
你是否檢查過'player.getName()。substring(0,player.getName().length()/ 2)'確實會返回玩家的暱稱?在我看來,它故意返回它的一半! (另外,如果暱稱或客戶ID是唯一的,那麼只使用唯一的一個 - 另一個只是開銷)。 – halfer 2012-04-14 11:03:24