I've implemented a method that return the result of a query on a SQL database. I just want the method to retur only a String[] which is the result of a query that select a column on the db. Here my code:
public class DBConnection {
private static Connection con;
private static Statement st;
private static ResultSet rs;
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/database","user","password");
st = con.createStatement();
}
catch (Exception ex)
{
System.out.println("Error: "+ex);
}
public ArrayList<String[]> doQuery (String query)
{
ArrayList<String[]> v = null;
String [] record;
int columns = 0;
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
v = new ArrayList<String[]>();
ResultSetMetaData rsmd = rs.getMetaData();
columns= rsmd.getColumnCount();
while(rs.next()) {
record = new String[columns];
for (int i=0; i<colonne; i++) record[i] = rs.getString(i+1);
v.add( (String[]) record.clone() );
}
rs.close();
stmt.close();
} catch (Exception e) { e.printStackTrace(); }
return v;
}
this method return an ArrayList object that contains the result of a query. Now, the question is: how can I have from this ArrayList object a String[] object that contains ONLY a column of the result?
(As information : The String[] object will be inserted in a JComboBox object)