i want fill my JTable with films.
I have class Film
public class Film extends MainComponent{
String title;
String year;
String genre;
//director
//actor
public Film(String title, String year, String genre, int id, int stars) {
super(id, stars);
this.title = title;
this.year = year;
this.genre = genre;
}
public String getTitle() {
return title;
}
public String getYear() {
return year;
}
public String getGenre() {
return genre;
}
@Override
public String toString() {
return "Film{" + "title=" + title + ", year=" + year + ", genre=" + genre +",id="+getId()+", stars="+getStars()+ '}';
}
}
And from DB i read my film records and create new instances of films and then i give them to vector.
public ResultSet select(String table, String where) {
try {
Statement sta = con.createStatement();
System.out.println( "SELECT * FROM " + table + " WHERE " + where );
return sta.executeQuery( "SELECT * FROM " + table + " WHERE " + where );
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
return null;
}
ResultSet rs;
Vector<Film> films = new Vector();
rs = db.select("films");
try{
while(rs.next()){
films.add(new Film(rs.getString("name"), rs.getString("year"), "Action", rs.getInt("id"), 5));
}
}catch (SQLException exc){
System.out.println("Error: " + exc);
}
Can anybody help me, how can i fill my JTable with my films to:
|Name|Year|Genre|
=================
|Batman|2010|Action|
...
...
Thanks for any response.