Sauvegarder image dans une base de donnees mysql

Résolu
profiter Messages postés 205 Date d'inscription mercredi 15 juin 2011 Statut Membre Dernière intervention 15 mars 2013 - 6 sept. 2011 à 19:51
cs_GodConan Messages postés 2113 Date d'inscription samedi 8 novembre 2003 Statut Contributeur Dernière intervention 6 octobre 2012 - 9 sept. 2011 à 06:35
bonjour,
j'ai trouvé sur internet des gens qui parle de ca mais sur le web alors une application java avec mysql j'ai pas trouvé de bon chose
la question est bien le ttre du forum
merci
A voir également:

13 réponses

profiter Messages postés 205 Date d'inscription mercredi 15 juin 2011 Statut Membre Dernière intervention 15 mars 2013 8
7 sept. 2011 à 08:10
j'ai trouvé :
voila la classe dao pour sauvegardé et afficher l'image dans mysql :
public class imprimer_DAO extends DAO<client> {

public void sauveIMG(String location, String name) throws Exception
  {
    File monImage = new File(location);
    FileInputStream istreamImage = new FileInputStream(monImage);

    try
    {
    	PreparedStatement ps = this.connect.prepareStatement("delete from image");
    	ps.executeUpdate();
    	ps this.connect.prepareStatement("ALTER TABLE image AUTO_INCREMENT 0");
    	ps.executeUpdate();
       ps = this.connect.prepareStatement(
          "insert into image (img) values (?)");
      try
      {
        //ps.setString(1, name);
        ps.setBinaryStream(1, istreamImage, (int) monImage.length());
        ps.executeUpdate();
      }
      finally
      {
        ps.close();
      }
    }
    finally
    {
      istreamImage.close();
    }
  }

public Image afficher() throws Exception
  {
    
      PreparedStatement ps = this.connect.prepareStatement("select img from image ");
      try
      {
        ResultSet rs = ps.executeQuery();;
        Image img = null ;
        
          while(rs.next())
          {
            img = ImageIO.read(rs.getBinaryStream("img" ));
            
          }
          return img ;
    }catch(Exception e){
    	System.out.println("erreur chargement image");
    }
return null;
    
    
  }


}


merci
4