MySQL help

Discussion in 'Spigot Plugin Development' started by RandomPanda30, May 26, 2015.

  1. Alright so I have this table at the moment :

    ID | player | name
    1 | RandomPanda30 | test1
    2 | Danmeal_ | test1
    3 | RandomPanda30 | test3
    4 | MrFro | test4

    As you can see I have RandomPanda30 twice in the player column and I could really use with getting the values from the name column. I was wondering how I could do this normally I'd just use SELECT ... FROM ... etc...
     
  2. do you want both results?
     
  3. Running an offline server or online?
    I had the same problem and went into each of my servers spigot.yml and made (bungeecord) to true.. it should fix it stacking.. make sure to check if the dB contains you so it doesn't keep adding you..
     
  4. Yes, I was thinking of putting them both in a list as strings although the problem is, I don't know how to do this but I was thinking I could get the auto incrementing ID and then loop through the IDs and get the value?

    Whut this is a custom database xD Although I'll keep this in mind to be honest, I know someone who's having this issue
     
  5. Well if you want both.. then 'SELECT * FROM `table` WHERE player = RandomPanda30" will actually return a result with both entries.

    So you could do something like this:

    Code (Text):
    List<String> names = new ArrayList<String>();

    ResultSet rs = sql.executeQuery("SELECT * FROM `table` WHERE player = 'RandomPanda30'");

    while(rs.next()){

        names.add(rs.getString("name"));

    }
     
    The above will make the List 'names' contain all the results for that player. In this particular case, it would contain 'test1' and 'test3'
     
    • Winner Winner x 1
  6. Works like a charm. Thank you!
     
  7. First, why using MySQL? For a mc, use MongoDB as your database. It is the best for MC, and easier I think.
     
  8. I don't understand why you put first even though you only had one point. Anyway, MySQL is usually easier to get setup and get running. I prefer MySQL over MongoDB and even some large servers use MySQL or even both.
     
  9. Nah, MySQL for Minecraft.. Wouldn't prefer it. Each his choice.
     
  10. I erm, don't see the difference between the two if I'm being honest .-. They both do the same thing right?
     
  11. In my opinion linking to the MongoDB site on a MongoDB vs MySQL comparison is just bad, the whole debate has been going on for ages.
     
  12. Why? They are not saying MongoDB is better or something. They just comparing those 2.
     
  13. It's likely to be biased if it has been written by them.[​IMG]
    for example, the above.

    Note that it is generally not always a preference. In some cases either of the databases can perform better.
     
  14. Well, "mc" isn't something you use a database for. In different scenarios MySQL or MongoDB (or SQL / NoSQL) databases are to be preferred.
    Just saying MongoDB is the solution for everything isn't correct.
     
  15. Completely irrelevant comparison.

    They do the same thing in the endgoal: store data. Outside of that, they're very different.

    If you're using MySQL, I'd recommend learning more about sql in general first. Your tables from what I've already seen could benefit from indexing, as well as a different table for player information. (Also, you shouldn't use SELECT * essentially ever in production sql code).

    For learning some basics:
    http://sqlzoo.net/

    Probably because they aren't even comparable and trying to say that one is better than the other makes as much sense as saying "I don't buy apple products because microsoft hates babies". Unless you really hate babies, I guess.
     
    • Winner Winner x 1
  16. Welcome to the debate section!

    I know the basics, I've remove the SELECT * and replace * with what I need. I used that for just getting the values (Or something, it's late here)

    And the rest of the debate is as follows...
     
  17. Learn about indexing, and try to look up some info on entity-relationship modelling. It will help you with creating a layout of your SQL database more easily and efficiently.