0
嗨我想打印到表格圖像中的單元格作爲一個網址。我有作爲文本存儲在我的數據庫表中的數據。 我把我用來打印其他列中的其餘數據的方法,我想添加圖像鏈接的另一列。如何使用mysql在jtable中顯示Url圖像?
任何幫助都會很好。
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 Poster,Title,Year,Country ,imdb ,Trailer from movie where Genre ='" + Genre + "'";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/whichmovie", "Asis", "dekrayat24");
System.out.println("Conectado a la base de datos SQLite");
st = con.createStatement();
rs = st.executeQuery(sql);
jTable1.setDefaultRenderer(Object.class, new IconCellRenderer());
DefaultTableModel model = new DefaultTableModel();
this.jTable1.setModel(model);
// Donde 50 es el tamaño que querramos en la celda según lo q necesitemos
jTable1.setRowHeight(55);
jTable1.setCellSelectionEnabled(true);
ResultSetMetaData rsMD = rs.getMetaData();
int numcolumnas = rsMD.getColumnCount();
for (int x = 1; x <= numcolumnas; x++) {
model.addColumn(rsMD.getColumnLabel(x));
}
if (!rs.next()) {
ResultadosLabel.setText("No Movies found ");
} else {
do {
Object[] fila = new Object[numcolumnas];
for (int i = 0; i < numcolumnas; i++) {
fila[i] = rs.getObject(i + 1);
byte[] imagedataCover = rs.getBytes("Poster");
format = new ImageIcon(imagedataCover);
byte[] imagedataCountry = rs.getBytes("Country");
format2 = new ImageIcon(imagedataCountry);
fila[0] = new JLabel(format);
fila[3] = new JLabel(format2);
ResultadosLabel.setText(i - 2 + " " + "Movies found ");
}
model.addRow(fila);
setAnchoColumnas();
} while (rs.next());
rs.close();
st.close();
con.close();
}
} catch (ClassNotFoundException ex) {
System.out.println(ex.getMessage());
}
}