MySQL finding if a value exists.

Discussion in 'Spigot Plugin Development' started by avighnash, Jun 17, 2016.

  1. This was not me! I'm sorry but my account was hacked.
     
  2. This was not me! I'm sorry but my account was hacked.
     
  3. Any suggestions / fixes?
     
  4. It still gives no message.
     
  5. For prepared statements, you don't use ' on the ?. Example would be "select something from somewhere where value=?"
     
    • Agree Agree x 2
  6. Still no luck :/
     
  7. Prepared statements are designed to prevent SQL injection and make your code look much more readable (IMO). That being said, in a prepared statement you need to insert ? where your values would be originally then set those values using the prepared statement's various mutator methods.

    So for example (Taken and modified from your code):

    Code (Text):
    String update = "UPDATE credits SET Amount=? WHERE Player=?";

    try (PreparedStatement statement = connection.prepareStatement(update)) {

        statement.setInt(1, amount);

        statement.setString(2, p.getUniqueId().toString());
    }
    You should defiantly look over a tutorial on SQL for Java. I'm not trying to be rude, but you're asking for more then just help. You're essentially asking for us to teach you how to use JDBC MySQL. You can find MANY MANY MANY tutorials spread throughout the internet (Even on spigot) that'll teach you all about using JDBC and SQL. Your current SQL structure is just incredibly messy and incorrect. You REALLY need to learn how to use JDBC before you write SQL and JDBC code.

    <- You can watch his various videos for a lot of basic information