Thread: Resultset

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Location
    Portugal
    Posts
    38
    Rep Power
    9

    Resultset


    Hi all, i wanted to develop a generic method to load content of tables from my MySql database into netbeans.

    What i want to know is if there is way to know how many values i get on each resultset line i have, so that with the .getString(column) i can pick each value.

    The code should be like the following, as example i'll use the select *:

    Code:
    public ResultSet FetchTable(String tablename)
        {
            try
            {
                Connection conn=GetConnection();
                String query= "SELECT * FROM " +tablename;
                Statement s = conn.createStatement();            
                s.execute(query);
                ResultSet rs = s.getResultSet();            
                while((rs!=null) && (rs.next()))
                {
                    
                                
                }
                s.close();
                conn.close();
                return rs;
            }
            catch(Exception ex)
            {
                System.out.println(ex);
                return null;
            }
        }
    Inside the while i would like to make a for cicle to do:
    rs.getString(columnid), so that i could keep the method available for all classes.
    Is it possible?
  2. #2
  3. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    Take a look at ResultSetMetaData. It can do what you want.

    Comments on this post

    • Revoh agrees

IMN logo majestic logo threadwatch logo seochat tools logo