• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Putting ResultSet into an Array list

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic