bonjour,
j'ai crée un colonne 'image' de type blob dans une table 'analyse ' dans ma base de donnée MYSQL . j'ai utilisé ce code dans le but stocker des images dans le colonne 'image'.Mais, ca ne fonctionne pas.merci d'avance.
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
 
 JFileChooser fc=new JFileChooser(); 
    fc.showOpenDialog(this);
    File f=fc.getSelectedFile();
    String path=f.getAbsolutePath();
    j5.setIcon(new ImageIcon(path));
    try
    { 
     FileInputStream fin=new FileInputStream(f);
    int len=(int)f.length(); 
    Class.forName("com.mysql.jdbc.Driver");
     con = getConnection("jdbc:mysql://localhost:3306/base_rapport_tt","root","");
    PreparedStatement ps1=con.prepareStatement("insert into analyse(image) values(?)");
    ps1.setBinaryStream(1, fin, len); 
    int status =ps1.executeUpdate();
    if(status > 0) 
    { j1.setText("Successfully inserted in DB"); 
    }
    else
    { 
            j2.setText("Image not inserted!"); 
            } 
    }
    catch(Exception e)
    {System.out.println(e);
    }