Hello, i am working on a javabean that is connecting to a database and executes an sql string. The javabean returns the records retrieved in a tabular format.
Currently i can achieve the above requireement, but only through using a simple table-formatted string, this is not dynamic and a 2d array approach would not be dynamic either.

I have read a little about using a dynamic approach, possiblya vector of objects, or array list of objects to solve the problem, but i don't really know how to start, could anybody help me??

The code i have so far is:

package webtech;

import java.sql.*;

public class questiona {
/* Step 1) Initialize Variables*/
String result = "";
String query = "select id, name, url, thumb_url, keywords, category, author from mytable;";

String url = "";
String driver = "";

String uname = "";
String dpass = "";


/*Step 2) Make a database connection*/
private Connection dbconn = null;
public questiona()
{
try
{
Class.forName(driver);
dbconn = DriverManager.getConnection(url, uname, dpass);
/*Create an SQL statement*/
Statement statement = dbconn.createStatement();

if (statement.execute(query))
{/*Step 3) If we have a result lets loop through*/
ResultSet results = statement.getResultSet();
ResultSetMetaData metadata = results.getMetaData();
/*Validate result. Note switch to while loop if we plan on multiple results from query*/
if(results != null)
{
/*Use results setmetadata object to determine the columns*/
int li_columns = metadata.getColumnCount();




result += " <tr>\n\r";
result += " <td>" + metadata.getColumnLabel(1) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(2) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(3) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(4) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(5) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(6) + "</td>\n\r";
result += " <td>" + metadata.getColumnLabel(7) + "</td>\n\r";
result += " </tr>\n\r";

/*loop throught the columns and append data to our table*/


while(results.next())
{
result += " <tr>\n\r";
result += " <td>" + results.getObject(1).toString() +"</td>\n\r";

result += " <td>" + results.getObject(2).toString() +"</td>\n\r";

result += " <td>" + results.getObject(3).toString() +"</td>\n\r";

result += " <td>" + results.getObject(4).toString() +"</td>\n\r";

result += " <td>" + results.getObject(5).toString() +"</td>\n\r";

result += " <td>" + results.getObject(6).toString() +"</td>\n\r";

result += " <td>" + results.getObject(7).toString() +"</td>\n\r";




result += " </tr>\n\r";
}
}
}
}
catch (ClassNotFoundException e)
{ result = "<tr><td> Error in database";
result += " <br/>" + e.toString() + "</td></tr>";
}

catch (SQLException e)
{ result = "<tr><td> Error in SQL";
result += " <br/>" + e.toString() + "</td></tr>";
}
finally
{
try {
if (dbconn !=null)
{ dbconn.close();}
}

catch (SQLException e)
{ result = " <tr><td> Error in closing connection.";
result += " <br/>" + e.toString() + "</td></tr>";
}
}
}
public String getResults() {
return result;
}
}