aspose file tools
The moose likes JDBC and the fly likes Putting ResultSet into an Array list Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Putting ResultSet into an Array list" Watch "Putting ResultSet into an Array list" New topic
Author

Putting ResultSet into an Array list

Kassi Hill
Greenhorn

Joined: Sep 29, 2003
Posts: 24
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.
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

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?
Kassi Hill
Greenhorn

Joined: Sep 29, 2003
Posts: 24
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.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Putting ResultSet into an Array list
 
Similar Threads
Resultset from Action class to JSP ?
How to connect applet to database
Use only 1 connection to SQL Server (newbie ?)
returning a ResultSet?
JavaBean Connect to Database, Which should return?