URL: https://linuxfr.org/forums/programmation-java/posts/insertion-d-image-dans-jtable Title: insertion d image dans jTable Authors: stoukou Date: 2005年06月02日T11:27:45+02:00 Tags: Score: 0 bonjour à tous, voila mon pbl est le suivant g des images dans la base [derby] sous forme de blob j essaye de les requeperer et de les afficher dans un jtable bon g ça comme code insertion dans la base Code: // insertion de la table £spaces£ £/spaces£public void insertion(int i) throws ClassNotFoundException, IOException, SQLException{ £spaces£ £/spaces£ £spaces£ £/spaces£File monImage = new File("xXx.bmp"); £spaces£ £/spaces£FileInputStream istreamImage = new FileInputStream(monImage); £spaces£ £/spaces£Connection conn = null; £spaces£ £/spaces£PreparedStatement stmt = null; £spaces£ £/spaces£int rs =0; £spaces£ £/spaces£//String query = "INSERT INTO HOTEL (NAME, HOTEL_ID, pic) " + £spaces£ £/spaces£// "VALUES ('NOVOTEL' ,"+i+","+pic+")"; £spaces£ £/spaces£try { £spaces£ £/spaces£conn = (new DriverJDBC()).initDriver(); £spaces£ £/spaces£stmt =conn.prepareStatement("insert into Hotel (name, HOTEL_ID, pic) values (?,?,?)"); £spaces£ £/spaces£stmt.setString(1, "NOVOTEL"); £spaces£ £/spaces£stmt.setInt(2,i); £spaces£ £/spaces£stmt.setBinaryStream(3, istreamImage, (int) monImage.length()); £spaces£ £/spaces£rs = stmt.executeUpdate(); £spaces£ £/spaces£ £spaces£ £/spaces£} catch (SQLException e) { £spaces£ £/spaces£System.out.println("Requete incorrecte"); £spaces£ £/spaces£e.printStackTrace(); £spaces£ £/spaces£} catch (ClassNotFoundException cnf) { £spaces£ £/spaces£System.out.println("La classe du driver jdbc n'a pu etre chargee"); £spaces£ £/spaces£cnf.printStackTrace(); £spaces£ £/spaces£} finally { £spaces£ £/spaces£try { £spaces£ £/spaces£conn=(new DriverJDBC()).shutDown(); £spaces£ £/spaces£} catch (SQLException e) { £spaces£ £/spaces£} £spaces£ £/spaces£} £spaces£ £/spaces£} recuperer les données de la base Code: £spaces£ £/spaces£public Vector recherche() throws ClassNotFoundException { £spaces£ £/spaces£ £spaces£ £/spaces£Connection conn = null; £spaces£ £/spaces£Statement stmt = null; £spaces£ £/spaces£ResultSet rs =null; £spaces£ £/spaces£Vector res = new Vector(); £spaces£ £/spaces£String query = "SELECT * FROM HOTEL"; £spaces£ £/spaces£try { £spaces£ £/spaces£conn = (new DriverJDBC()).initDriver(); £spaces£ £/spaces£stmt = conn.createStatement(); £spaces£ £/spaces£rs = stmt.executeQuery(query); £spaces£ £/spaces£while (rs.next()) { £spaces£ £/spaces£HotelModel h = new HotelModel(); £spaces£ £/spaces£h.setId(rs.getInt("HOTEL_ID")); £spaces£ £/spaces£h.setPic(rs.getBlob("pic")); £spaces£ £/spaces£h.setNom(rs.getString("NAME")); £spaces£ £/spaces£res.add(h); £spaces£ £/spaces£} £spaces£ £/spaces£ £spaces£ £/spaces£stmt.close(); £spaces£ £/spaces£ £spaces£ £/spaces£} catch (SQLException e) { £spaces£ £/spaces£System.out.println("Requete incorrecte"); £spaces£ £/spaces£e.printStackTrace(); £spaces£ £/spaces£} catch (ClassNotFoundException cnf) { £spaces£ £/spaces£System.out.println("La classe du driver jdbc n'a pu etre chargee"); £spaces£ £/spaces£cnf.printStackTrace(); £spaces£ £/spaces£} finally { £spaces£ £/spaces£try { £spaces£ £/spaces£conn=(new DriverJDBC()).shutDown(); £spaces£ £/spaces£} catch (SQLException e) { £spaces£ £/spaces£} £spaces£ £/spaces£}return res; £spaces£ £/spaces£} le probleme est la je sais pa comment inserrer les images dans les cellule du jtable Code: £spaces£ £/spaces£//remplir la table £spaces£ £/spaces£for (int i = 0; i < v.size(); i++) { £spaces£ £/spaces£HotelModel h = (HotelModel) v.elementAt(i); £spaces£ £/spaces£mTable.setValueAt(String.valueOf(h.getId()), i, 0); £spaces£ £/spaces£mTable.setValueAt(h.getNom(), i, 1); le probleme est la !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! £spaces£ £/spaces£mTable.setValueAt(h.getPic(), i, 2); £spaces£ £/spaces£ merci d'avance