Videanu Adrian
Videanu Adrian

Reputation: 970

j2se application best practice

i want to build a simple CRUD console application which consists of a set of 10-20 classes that need access to CRUD methods. I do not want to create a connection each time in every method that needs db access. Maybe put all the creation part into a separate singleton class ?
Any ideas, best practices how this kind of application should be structured ?

Upvotes: 0

Views: 364

Answers (3)

madth3
madth3

Reputation: 7344

A quick but overeengineered solution for simple CRUD would be to use Netbeans JPA wizards:

  • Entity Classes from Database (Check the Adding Entities part of this)
  • JPA Controller classes from Entities (Small sample)

No handling connections needed.

Upvotes: 1

mprabhat
mprabhat

Reputation: 20323

Just one tutorial is sufficient to learn How to design DAO

Upvotes: 1

Harshavardhan Konakanchi
Harshavardhan Konakanchi

Reputation: 4294

Create a base class with all the functionalities as a seperate method. For example as follows.

Connection getConnection() - returns connection object

void close() - closes the connection

Like this implement method for each functionality. Extend your operations class to this base class and call required functions.

Ex:

 public class Insert extends Base {

// call the rquired functions

}

If needed you can parametetrise some variables like drivernames, url, username , password etc.,

Upvotes: 0

Related Questions