Tutorial Using MySQL In your Plugins!

Discussion in 'Resources' started by -_Husky_-, Mar 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    z0ckyZockt

    Hey guys,

    I have a problem.

    These is my code:
    Code:
    package Main;
    
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import MySQL.MySQL;
    
    public class one extends JavaPlugin{
       
       
        MySQL MySQL = new MySQL(plugin, "**********", "3306", "LoginSecurity", "********", "**********");
        Connection c = null;
       
        @Override
        public void onEnable() {
           
            c = MySQL.openConnection();
           
        }
       
        Statement statement = c.createStatement();
       
        public void OnJoin(PlayerJoinEvent e){
            Statement statement = c.createStatement();
            ResultSet res = statement.executeQuery("SELECT * FROM users WHERE UUID = '" + e.getPlayer().getUniqueId().toString() + "';");
            res.next();
           
            if(res.getString("UUID") == null){
                statement.executeQuery("INSERT INTO users (`id`, `UUID`) VALUES (`null`, `"+ e.getPlayer().getUniqueId().toString() +"`);");
                e.getPlayer().sendMessage("/register <passwort>");
               
            }
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
           
            Player p = (Player) p;
           
            if(cmd.getName().equalsIgnoreCase("register")){
                ResultSet res1 = statement.executeQuery("SELECT password FROM users WHERE UUID = '" + p.getUniqueId().toString() + "';");
                if(res1.getString("password") == null){
                    if(args.length == 0){
                        p.sendMessage("/register <password>");
                    } else if(args.length == 1){
                        String pw = args[0];
                        statement.executeQuery("UPDATE `users` set `password` = '"+ pw +"' WHERE UUID = " + p.getUniqueId().toString() + ";");
                        p.sendMessage("Du hast dich erfolgreich registriert!");
                        p.sendMessage("/email <email>");
                    }
                } else {
                    p.sendMessage("Du hast dich schon Registriert! (/login <password>)");
                }
               
                return true;
            }
           
            if(cmd.getName().equalsIgnoreCase("email")){
                ResultSet res2 = statement.executeQuery("SELECT email FROM users WHERE UUID = '" + p.getUniqueId().toString() + "';");
                if(res2.getString("email") == null){
                    if(args.length == 0){
                        p.sendMessage("/email <email>");
                    } else if(args.length == 1){
                        String email = args[0];
                        statement.executeQuery("UPDATE `users` set `email` = '"+ email +"' WHERE UUID = " + p.getUniqueId().toString() + ";");
                        p.sendMessage("Du hast deine Email-Adresse erfolgreich hinterlegt!");
                    }
                } else {
                    p.sendMessage("Du hast schon eine Email-Adresse hinterlegt!");
                }
                return true;
            }
           
           
            return false;
        }
       
        @Override
        public void onDisable() {
           
            MySQL.closeConnection();
           
        }
       
       
       
    }
    
    I have an error on line 18.

    Line 18:
    Code:
     MySQL MySQL = new MySQL(plugin, "*********", "3306", "LoginSecurity", "*******", "*******"); 
    The error ist plugin but i don't know to fix it.
    Can anyone help me?

    Sorry for my bad english.
     
  2. Offline

    timtower Moderator Moderator

Thread Status:
Not open for further replies.

Share This Page