Hi i am working on the website development and i want to know using Singleton Pattern for Database Connection for Website is Good Idea or not ? and if i use Singleton Pattern for Website means There are some Actions (java files ) which close connection object explicitly at that time i am getting Connection Closed Error How to Rectify this ?
When you are handling Singleton Connection pattern for the DB connections, You have to closely watch the Connections objects handled in the other methods. You should never close the DB connections explicitly in any methods. Hope you might have closed the DB Connection somewhere inside the method and when the other method gets the DB connection, as you have declared the DB connection as static and closed earlier you have received this error. Steps to follow:
1. Create static connection in the class.
2. Receive the connection in methods and dont close it anywhere. Close only Stement,ResultSet..etc.
3. If you want to close Connection object , then Implementing Singleton Pattern is not the Right choice. Use others.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ever since I found this suit I've felt strange new needs. And a tiny ad: