1

So I have an array of PlayerNames that are in a specific 'clan' that I need to save, so when I load the server it will loop through all of the entries.

Here is what I currently have MySQL Table

enter image description here

Not sure what I would put for the 'members' basically what I want is to store UUID's of an array I have. It can come out as a string but I just need them to be able to store like

members: uuid, uuid, uuid, uuid

I understand how to build the connection, ResultSet, and the Statement part, I just don't know how to make MySQL know that I am trying to save these list of members as an array. Any help would be appreciated, I apologize if I did something wrong.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Eggspurt
  • 63
  • 1
  • 9
  • your image is not working – beastlyCoder Jan 01 '17 at 01:05
  • Welcome to SO. Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) And [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) And how to create a [Minimal, Complete and Verifiable example](http://stackoverflow.com/help/mcve) – RiggsFolly Jan 01 '17 at 01:13
  • I believe it's the website, I simply uploaded a picture via stackoverflow. – Eggspurt Jan 01 '17 at 01:13
  • That looks like a database design mistake. Look at a basic database design tutorial/book – RiggsFolly Jan 01 '17 at 01:17
  • did you try my answer? – e4c5 Jan 03 '17 at 07:27

1 Answers1

0

The problem here is in your data structure. It's not Normalized where as RDBMS are designed to store normalized data. All Create/Update/Delete/Retrieve operations become a lot easier if the data is normalized.

To normalize your tables, you need to stop storing member ids in the same column as CSV.

The Gang table should

uuid
title
kills

I assume you already have a members table and it looks something like

uuid
member_name

Then you need a new table called gang_members

gang_id
member_id

And create a unique index on those two columns.

Also see https://stackoverflow.com/a/41215681/267540 , Is storing a delimited list in a database column really that bad? and https://stackoverflow.com/a/41305027/267540

Community
  • 1
  • 1
e4c5
  • 52,766
  • 11
  • 101
  • 134
  • Thanks for this incite this makes sense, so in my code I should make some sort of way to give ID's to each gang that created and on startup check all of the members in the MySQL DB for their Clan ID if they have one -1 meaning they don't. And add them to the object that way? – Eggspurt Jan 04 '17 at 02:11
  • yes, taht's about it. When you insert a new item, mysql gives you what's know as the LAST_INSERT_ID which makes it easy to create related entries in the other tables – e4c5 Jan 04 '17 at 02:45