Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

using database in swing project

I have to develop a Swing Project. I need to access the database in various places. So how should I arrange the classes so that there is one database class. Should I use inheritance for that. Just a brief outline. I'm a java(struts/spring/hibernate) developer but its going to be my first Swing Application.

Upvotes: 2

Views: 485

Answers (2)

Lajos Arpad
Lajos Arpad

Reputation: 76436

A few ideas:

  • I think you should use an ORM (like OrmLite, for example) in your application

  • Create a package which will contain interfaces or abstract classes for your data access layer.

  • Create another package where your interfaces and abstract classes (of the data access layer) are implemented (these implementations should contain all your direct commands to the database)

  • Create another package, where you will have your business layer. The methods of your classes in this package should use the data access layer through the interfaces and combine them to solve any business-logic-level problem

  • You should access directly your business layer classes from the backend part of your application which should be separated from your user interface as much as possible

Upvotes: 5

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

Inheritance? No, rather you'd use composition. Accessing a database is no different for a Swing application than a non-Swing application with a few caveats:

  • Do all database access off of the main Swing event thread or event dispatch thread (EDT).
  • Do most all Swing calls on the EDT.
  • If the data will change dynamically will need to read up on ways to listen for data changes and bind the data to your display.

Upvotes: 7

Related Questions