您好我想将数据从mysql查询打印到我的Jtable,我知道如何打印常规数据(String),但不知道如何用图片来做。我需要的是在桌子的第一个单元格中打印图片。
public void SearchMovie() throws SQLException {
try {
Connection con = null;
ResultSet rs = null;
Statement st = null;
String Genre = ComboGenero.getSelectedItem().toString();
String Era = ComboEra.getSelectedItem().toString();
String Clsssification = ComboClasification.getSelectedItem().toString();
String sql = "select Foto,Title,Year,Country ,Rating from movie where Genre ='" + Genre + "'";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/whichmovie", "Asis", "dekrayat24");
st = con.createStatement();
rs = st.executeQuery(sql);
DefaultTableModel model = new DefaultTableModel();
this.jTable1.setModel(model);
jTable1.setDefaultRenderer(Object.class,new IconCellRenderer());
jTable1.setRowHeight(40);
ResultSetMetaData rsMD = rs.getMetaData();
int numcolumnas = rsMD.getColumnCount();
for (int x = 1; x <= numcolumnas; x++) {
model.addColumn(rsMD.getColumnLabel(x));
}
while (rs.next()) {
Object[] fila = new Object[numcolumnas];
for (int i = 0; i < numcolumnas; i++) {
fila[i] = rs.getObject(i + 1);
ResultadosLabel.setText(numcolumnas + "Movies found");
}
model.addRow(fila);
}
rs.close();
st.close();
con.close();
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
谢谢。