English 中文(简体)
办公室 Java swing JList Element to/ from MySQL
原标题:save/restore Java swing JList Element to/from MySQL

I m New to Java (and swing) and search a way to Save (and reload it subsequently) all JList elements to Database or in particular MySQL. 我阅读了Java Serializable,不能找到工作守则供参考。

最佳回答

空中化不是答案。 你们想要做的是控制器,能够激活JList模型类别,并将每个项目的数据节省到数据库。

String[] data = {"one", "two", "three", "four"};
JList dataList = new JList(data);

for(int i = 0; i < dataList.getModel().getSize(); i++) {
    String item = (String)dataList.getModel().getElementAt(i);
    saveItemToDatabase(item);
}

这样,你就只能将数据保存到数据库,而不是清单中的“情报调查”部分,以及试图将联合名单序列化的所有其他轨道。

Edit: 为节省整个模式,我仍会单独而不是BLOB节省这些项目。 因此,为了从数据库中检索数据,你会做一些类似的事情。

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;
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签