I am working on a class that will connect to an MS Access database using the JDBC/ODBC bridge driver. I have two questions. 1) can I create a method with the class that connects to the database only and then call that method to connect each time I need it? IE: public void openConnection(), if so do I need a return type? Can I return a connection? My second question is once I execute an SQL statment, can I put the ResultSet into an ArrayList and then return the list to the calling method? Any advice you can give me would be very helpful. Thank you.
You should have no problem creating the class you want. I use a similar class to return a connection when I need it. It uses somewhat of a singleton pattern in that if there is already a connection, I just return it, otherwise I open a new connection. If it is a standalone application this is a good idea. If this is for a web app, use a Connection Pool. Major psuedo code:
Just make sure you are using static methods and objects in your class for the connection. Now, about putting a ResultSet into an ArrayList. The answer to your question is yes:
But a good question for you is why do you need to do that?
Joined: Sep 29, 2003
I am working on a project with other people and my job is to write the DataAccess classes. When we were doing our UML diagrams there are several methods that need the information returned in array's. Thank you for your help. I will use your suggestions in my general DataAccess class that I am working on to see how it works. Thank you again.