
December 12th, 2012, 06:51 AM
|
|
Contributing User
|
|
Join Date: Mar 2007
Location: Portugal
Posts: 38
  
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?
|