简体   繁体   中英

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 ?

只需一本教程就足以学习如何设计DAO

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.

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.,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM