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?
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
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): SELECT STRING FROM Strings WHERE STRING = '<...>' ^^see how confusing your table and column names are? Change it... Or i guess you could use something like Code (MySQL): COUNT(SELECT STRING FROM Strings WHERE STRING = '<...>')
create a PreparedStatement, iterate over your values, set the values and call addBatch(). After you're done iterating, call executeBatch()
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.
make sure u run ur stuff off the main thread, also when creating columns use exact values, dont go 'extra' just to 'make sure' ex: 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