-1

Hi am creating a instant messenger in java, I am very unsure as to what the best way to store a users contacts would be. I am using a mySQL database to check user credentials for login, once logged in the user status on the database is stored as "online". I have created a simple GUI for the client with a login section and a textArea for the contacts. is the best way forward to store the contacts in the mySQL databse too? or in a file which can be uploaded to the mySQL database. and how would i get the contacts list to update as users go online and offline. currently I have no code for updating or storing contacts as I am lost, if someone could please send me in the write direction I would be grateful.

here is what I have

Java chat client GUI -login feature working which stores the user as online on the mySQL database

-mySQL database which stores users Id, password, name and status as well as ipAddress

I am stuck here and need help please. for example... when a user logs in from their client and another user logs in from theirs and they are both contacts how will can i get their "online" statuses from the sql database and output them. I know i will user a textArea etc but would i need to implement RMI? or will my server need to handle all of this.

1 Answers1

1

You should create a new database table, and store the owner of the contact list and his contacts, with the following columns:

OwnerIDContactList (Primary key | Foreign key of UserID in Users Table) & UserIDInContactList(Primary key | Foreign key of UserID in Users Table)

and then you should 'link' the contacts of the logged in user to a listbox or something similar to it.

You have to use many to many relationship for that table. You can find more about many to many relationship of the same type here: How to make SQL many-to-many same-type relationship table

Community
  • 1
  • 1
George Chondrompilas
  • 3,167
  • 27
  • 35
  • so then this would create a unique table for each user to store his or her contacts? if i use one table like you have suggested it wouldnt reflect many to many? – user3252991 Apr 18 '14 at 13:36
  • No, you should create one table which will store the contact list of users of every user. It is a many to many relationship. You can find more about many to many relationship here: http://stackoverflow.com/questions/18603372/how-to-make-sql-many-to-many-same-type-relationship-table – George Chondrompilas Apr 18 '14 at 23:51