I am creating a Java connection to a MySQL database and I have several different classes which will be utilizing that connection for various purposes. This will involve different MySQL user accounts where the user logs in to the database and performs the necessary actions.
So, I guess my question is: Is there a way to create a Connection class for a persistent connection to the database, so long as a specified user is logged into the system, that can be reused in other classes for authentication? If so, how can I use
If I am trying to go about this all wrong then let me know that as well.
Any help would be very....Helpful!
Bryan Scarbrough<br /> <br />Consistency is the last resort of the unimaginative!
A connection is tied to a user. While you can keep open a connection and pass it around to different classes, it will always be for that specific user. For a different user, you have to open a new connection.
You can make it a static method in some utility class. That way you can access it from everywhere. The Class.forName().getInstance() only needs to be done once - you don't need to repeat it for every connection.