DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005
    Posts
    1

    Storing ArrayList from ResultSet

    hey guys,
    I am trying to store into my arraylist a couple of objects that is being referenced from sybase (i do not have the connections in yet so dont worry about that part). But when i run a dummy example of this it is not working correctly. Should i create a project class and create an object with those values then store them into the project_table arraylist class? here is my code

    public class Project_Table
    {
    Private int table_size;
    ArrayList Project_Table_List;

    Project_Table()
    {
    table_size = 0;
    Private int xproject_ID = 0;
    Private String xproject_Name = null;
    Project_Table_List = new ArrayList();
    }

    add(int ID, String Name)
    {
    xproject_ID = ID;
    xproject_Name = Name;
    table_size++;
    Project_Table_List.add(xproject_ID, xproject_Name)
    }
    }

    import Project_Table
    public class Query_Class()
    {

    Project_Name_Query(int xtype_ID)
    {
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("Select Project_ID, Project_Name FROM Project_Table WHERE Type_ID = " + Integer.toString(xtype_ID));
    if(rs != null)
    {
    while(rs.next())
    {
    Project_Table.add(rs.getInt(Project_ID), rs.getString(Project_Name));
    }
    }
    }
    }

    thanks
    Randy

  2. #2
    Join Date
    Dec 2003
    Location
    tx/us
    Posts
    131
    I like to work only with the app's objects so I'd define a Project and maybe a full constructor so I could do something like this.
    Code:
    while (rs.next())
    {
        projectList.add(new Project(rs.getInt(Project_ID), rs.getString(Project_Name));
    }
    Of course this is a simple example but in general things get really messy really fast if you start passing things that directly represent database rows around your business logic.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links