Save/restore Java swing JList Element to/from MySQL?

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.

Up vote 0 down vote favorite share g+ share fb share tw.

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. Java swing jlist link|improve this question edited Oct 21 '10 at 1:22 asked Sep 24 '10 at 9:36khairil195 100% accept rate.

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. String data = {"one", "two", "three", "four"}; JList dataList = new JList(data); for(int I = 0; I GetElementAt(i); saveItemToDatabase(item); } 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 dataList. SetListData(loadModelFromDatabase()); public Vector loadModelFromDatabase() { Vector listModelData = new Vector(); ResultSet res = conn.

PrepareStatement("SELECT * FROM listmodel").executeQuery(); while(res.next()) { listModelData. Add(res. GetString(1)); } return listModelData; }.

I'm hoping to get a sample demonstrating how to save the whole ListModel Object from my JList.getModel() method into one BLOB field in database so that I can reload it later easier by using JList.setModel() method. – khairil Sep 25 '10 at 5:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions