je réussi a extraire des blobs et a les passer en images java (des instances de la classe Java "Image") grace a la methode suivante :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
     * private method used for retrieving an image by knowing its generic part ID
     * this method converts the Blob stored in DB in a java object "Image"
     * @param id
     * @return : a java "Image"
     */
    private Image retrieveImageByID(Integer id) {
        if (id==null) {
            System.out.println("DBPicker: can not retrieve an image with part's ID null");
            return null;
        }
        else {
            try {       
                Statement stmt = connection.createStatement();          
                String query = "SELECT image FROM generic_part WHERE id = " + id;
 
                // copy the image from the DB to Blob.
                ResultSet rs = stmt.executeQuery(query);    
                if(rs.next()) {
                          // "1" because the blob is the only field retrieved by the query : 
                          Blob blob = rs.getBlob(1); 
                          InputStream in = blob.getBinaryStream();
                          Image image = ImageIO.read(in);
                          return image;
                }
              }
              catch (Exception ex){
                  ex.printStackTrace();
              }
              System.out.println("DBPicker: Warning, image with part's ID :"+id + 
                      "can not be loaded");
              return null;
        }        
    }
mais j'aimerai bien faire l'opération inverse pour sauvegarder des images dans la base à partir de mon application. voyez-vous comment faire ?