I’m new to Java (and swing) and looking for a way to save (and reload it later) all JList elements to Database or in particular MySQL. I read about Java Serializable and cannot find a working code for reference.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Serialization is not the answer. What you want to do is have a controller that can iterate of the JList Model class, and save the data from each item to a database.
This way, you are only saving the data to the database, and not the UI part of the list, and all the other bits around it that trying to serialize the Jlist would do.
Edit: To save the whole model I would still save the items individually, rather than a BLOB. So, to retrieve the data back from the database, you would do something like