Database Connection
-
I have a manager class which works as a proxy for connecting to mysql database. I have 2 methods in it, ConnectToDatabase and ExecuteQuery. How should I write the class? Should I make it singleton? Else, if I initiate the class each time, won't it take delay to connect to database?? Thanks in advance Anvesh
-
I have a manager class which works as a proxy for connecting to mysql database. I have 2 methods in it, ConnectToDatabase and ExecuteQuery. How should I write the class? Should I make it singleton? Else, if I initiate the class each time, won't it take delay to connect to database?? Thanks in advance Anvesh
anveshvm wrote:
Else, if I initiate the class each time, won't it take delay to connect to database??
Initialization of your proxy class will not affect the delay to connect to database. And I don't think you need a singleton implementation here.
Navaneeth How to use google | Ask smart questions
-
anveshvm wrote:
Else, if I initiate the class each time, won't it take delay to connect to database??
Initialization of your proxy class will not affect the delay to connect to database. And I don't think you need a singleton implementation here.
Navaneeth How to use google | Ask smart questions
-
What about the connection object?? Should I keep the object static for the entire program execution scope. Or should I connect to the database, each time, I have to execute a query?
anveshvm wrote:
Or should I connect to the database, each time, I have to execute a query?
Yeah. That's the right approach.
anveshvm wrote:
Should I keep the object static for the entire program execution scope.
You can keep it if the object is very expensive to build each time. But if it is a simple proxy class, keeping instance will not give performance difference.
Navaneeth How to use google | Ask smart questions
-
anveshvm wrote:
Or should I connect to the database, each time, I have to execute a query?
Yeah. That's the right approach.
anveshvm wrote:
Should I keep the object static for the entire program execution scope.
You can keep it if the object is very expensive to build each time. But if it is a simple proxy class, keeping instance will not give performance difference.
Navaneeth How to use google | Ask smart questions