Check account player

Discussion in 'Plugin Development' started by Failede, Apr 20, 2014.

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

    Failede

    I'm trying to check if the user account exists
    Code:
    Player player = event.getPlayer();
    String query = String.format("SELECT * FROM `USERS` WHERE `PLAYERNAME` = '%s'", player.getName());
    ResultSet res = null;
    try {
    res = sqlite.query(query);
    res.next();
    } catch (SQLException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    this.getLogger().info("Failed query " + query + "!");
    }
    try {
    if(!res.next())
    {
    player.sendMessage(ChatColor.GREEN + "Witaj " + ChatColor.BLUE + player.getName() + ChatColor.GREEN + "!\nTwoje konto jest " + ChatColor.RED + "niezarejestrowane\n" + ChatColor.GREEN + "Jeśli chcesz cieszyć się darmową rozgrywką na naszym serwerze użyj komendy\n" + ChatColor.GOLD + "/rejestracja <hasło> <powtórz hasło>");
    frozen.add(player.getName());
    player.getInventory().clear();
    }
    else
    {
    player.sendMessage(ChatColor.GREEN + "Witaj " + ChatColor.BLUE + player.getName() + ChatColor.GREEN + "!\nTwoje konto jest " + ChatColor.BLUE + "zarejestrowane\n" + ChatColor.GREEN + "Jeśli chcesz cieszyć się darmową rozgrywką na naszym serwerze użyj komendy\n" + ChatColor.GOLD + "/logowanie <hasło>");
    frozenl.add(player.getName());
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    

    Unfortunately, even if there is, it gives me the message that I need to register. I tried to do it in a thousand ways. no effect
     
  2. Offline

    TheMcScavenger

    I made a login form with JavaFX a while back, maybe it helps you, maybe it doesn't.. It connects to a MySQL server, gets the data it needs, and gets the f.... out.

    Code:
    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection("IP, Port, Table, Username, Password");
    statement = connection.createStatement();
     
    String query = "select * from users";
    results = statement.executeQuery(query);
     
    users = new ArrayList<String>();
    while(results.next()){
        users.add(results.getString("username"));
    }
               
    results.close();
    statement.close();
    connection.close();
     
    if(users.contains(usernameField.getText())){
        // username already in use
    }
     
  3. Offline

    RainoBoy97

    Try removing the res.next() after the res = sqlite.query(query) line.
     
  4. Offline

    Failede

    I used SQLite...

    Don't work :<

    I convert ResultSet to integer and print...
    My 'res' is equal to zero :<
    Ahh... This is It was my fault, bad code, but I still do not know why it does not work
     
  5. Offline

    TheMcScavenger

    Failede I know, but that doesn't mean it's better. Like I said, maybe it helps you, maybe it doesn't. All I know is that it works perfectly, and that it's quite easy to use.
     
  6. Offline

    Failede

    We currently do not have a MySQL server: <
     
Thread Status:
Not open for further replies.

Share This Page