0

I'm coding a global bansystem for a Minecraftserver for Bungeecord (in Java). When a player, who is banned, tries to join, he should get kicked with the reason. I try to get the reason from a MySQL-table.

Here's the important Code:

PreparedStatement psn = null;
psn = Methoden.getConnection()
        .prepareStatement("SELECT Grund FROM BanList WHERE Name = '" + pn + "'");
if (psn != null) {
    ResultSet rsn = psn.executeQuery();
//  JDBC4ResultSet rsn = (JDBC4ResultSet) psn.executeQuery();
    if (rsn.next() == true) {
        ev.setCancelReason(
                "\2474[\2476Minepedia\2474]\n\247bDu wurdest aus folgendem Grund gebannt:\n\247c"
                        + rsn.toString()
                        + "\n\247bWenn du denkst, dass es ein Versehen war, dann schreib bitte eine Email an \[email protected]\247b!");
        ev.setCancelled(true);
    }
}

It doesn't matter if I use ResultSet or JDBC4ResultSet, I always get com.mysql.jdbc.JDBC4ResultSet@65cda838.

1 Answer 1

4

Applying the .toString() method to a ResultSet object will return a string representation of the ResultSet object itself, not the contents of the ResultSet. In your case, the ResultSet object's string representation is "com.mysql.jdbc.JDBC4ResultSet@65cda838".

You will want to use rsn.getString(1) or rsn.getString("Grund") to retrieve the value returned when you do rsn.next().

By the way, you're using your PreparedStatement incorrectly as well. You should be doing

prepareStatement("SELECT Grund FROM BanList WHERE Name = ?);

followed by

psn.setString(1, pn);

before you do the .executeQuery().

1
  • Yeah, it is working, but after the reason there is a little "cr" or something like this. What is it and why is it there? Tank you :) EDIT: I managed it with substring, so it is working now :) Thank you very much!!!
    – LeWimbes
    Nov 27, 2015 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.