开发者

How to store and retrieve object of a swing component in database, java

开发者 https://www.devze.com 2022-12-26 06:55 出处:网络
Hi I have written a small java program based on swing application. Now I want to store the object of my swing application (jframe) in database and I want to retrieve the same from database when its ne

Hi I have written a small java program based on swing application. Now I want to store the object of my swing application (jframe) in database and I want to retrieve the same from database when its necessary. during retrieve i want to get the same object. I am using sqlite as database

How to achieve this functionalit开发者_如何学Pythony

Thanks Sunil Kumar Sahoo


Are you sure you want to store the view and not the Model? Another method except for Preferences is to use XMLEncoder


I don't know about sqlite, but Preferences is a a good way to store information about your JFrame.


To my knowledge it's not actually possible to save the JFrame to a database. Whether you do it yourself or with some kind of library the way it works is that you save to the db all the information you need to recreate your JFrame.


A JFrame implements Serializable so theoretically it is serializable as an ObjectStream you could use ObjectInputStream and ObjectOutputStream and write the stream to the database.

All components in the JFrame should also be serializable. However it is not really advised to do this since the api says "Serialized objects of this class will not be compatible with future Swing releases."

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号