MySQL get info

Discussion in 'Spigot Plugin Development' started by Eliminator, Apr 18, 2017.

  1. What is the best way to save a list of Strings to a MySQL DB, then check if a certain string is in it?

    Do I need to:
    Code (Text):
    for(String s : stringList)
            statement.executeUpdate("INSERT INTO Strings (STRING) VALUES ("+s+");");
    Then "SELECT * FROM Strings;", and loop through it each time?
  2. If you look for a specific String, you can use something like this:
    Code (Text):
    SELECT * FROM table WHERE myKey = 'myValue';
    Then check if it returns something.

    But I'm not sure, if it's what you are looking for :confused:
  3. Can I store a list of only keys into a DB, with no values?
  4. First of, you shouldn't call your table, neither your column anything by string. "String" is the format / type. Using it as name is highly confusing.

    You could use a SELECT like @CodeHat suggests and check the amount of resulting rows:
    Code (MySQL):
    ^^see how confusing your table and column names are? Change it...

    Or i guess you could use something like
    Code (MySQL):
    • Agree Agree x 1
  5. This would be a table with 1 column. Of course it's possible.
  6. How would I do that? Just this?: INSERT INTO Words MyWord
  7. create a PreparedStatement, iterate over your values, set the values and call addBatch(). After you're done iterating, call executeBatch()
  8. Code (MySQL):
    CREATE TABLE `TableName` ( `ColumnA` VARCHAR(256) )
    Would create a table called TableName with 1 column called ColumnA, this would be a representation of a List.
  9. FrostedSnowman

    Resource Staff

    make sure u run ur stuff off the main thread, also when creating columns use exact values, dont go 'extra' just to 'make sure'

    if you're storing the player's name, don't use VARCHAR(200)

    you'd want to use VARCHAR(16) since 16 is max characters for minecraft username