Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 12th, 2012, 06:51 AM
Revoh Revoh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Location: Portugal
Posts: 38 Revoh User rank is Corporal (100 - 500 Reputation Level)Revoh User rank is Corporal (100 - 500 Reputation Level)Revoh User rank is Corporal (100 - 500 Reputation Level)Revoh User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 6 h 34 m 46 sec
Reputation Power: 8
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?

Reply With Quote
  #2  
Old December 12th, 2012, 01:34 PM
stdunbar's Avatar
stdunbar stdunbar is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: May 2004
Location: Superior, CO, USA
Posts: 2,398 stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level)stdunbar User rank is General 10th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 18 h 10 m 50 sec
Reputation Power: 1660
Send a message via Yahoo to stdunbar Send a message via Google Talk to stdunbar
Take a look at ResultSetMetaData. It can do what you want.
Comments on this post
Revoh agrees!
__________________
Need Java help? Want to help people who do? Sit down with a cup of Java at the hotjoe forums.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Resultset

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap