-
Connection to data base
Hello, I have a class that allows me to establish a connection with a data base and I have other classes singleton that uses the first that I described obtaining a connection. By each method in which I use the connection, first I open the data base, I use it and thenI close it.
Something like this:
Code:
Connection conn = new Connection ();
conn.openBase();
.............. something of code.......
conn.close();
This works, simply I want to know if it is correct to do it in this way, or if it is possible to improved it.
Daniel :o
-
hello! you could use singleton pattern, hereby you avoid, ( in case of having 500 users), to have 500 objects Connection thing that waste memory.
Albert
-
If it is an application Web, and it is going to have many consults. I advise to you to read a little of Connection Pool to increase the performance and make the system more robust from the point of view of the concurrent consultations…
The code that you showed didn't say a lot, because you encapsulate everything in Connection. of which there are no details…
Eric