Reputation: 970
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
Reputation: 7344
A quick but overeengineered solution for simple CRUD would be to use Netbeans JPA wizards:
No handling connections needed.
Upvotes: 1
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