package Base_données; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.filechooser.FileNameExtensionFilter; import java.sql.*; public class Loading extends JFrame{ private JFileChooser chooser=new JFileChooser(); private JLabel labelimg = new JLabel(); private Connection connection; private Statement statement; private String blob; public Loading() { this.setTitle("S'inscrire"); this.setForeground(Color.YELLOW); this.setBounds(400,100,500,500); this.setResizable(false); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.getContentPane().setBackground(Color.white); this.setLayout(null); labelimg.setBounds(150,30,200,200); labelimg.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.blue)); this.add(labelimg); JButton bouton1=new JButton("Parcourrir une image"); bouton1.setBounds(250,300,50,30); bouton1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String req="INSERT INTO test(IMAGE) VALUES(?)"; try { Class.forName("org.sqlite.JDBC"); String url="jdbc:sqlite:BDD/Mamesse.sqlite"; String utilisateur="root"; String password=""; connection=DriverManager.getConnection(url); // statement=connection.createStatement(); InputStream file=new FileInputStream(new File(blob)); // statement.execute(req); PreparedStatement prepared=connection.prepareStatement(req); prepared.setBlob(1, file); prepared.execute(); JOptionPane.showMessageDialog(null, "ENREGISTRÉES"); } catch (Exception e) { JOptionPane.showMessageDialog(null,e); e.printStackTrace(); } } }); this.add(bouton1); // JButton bouton=new JButton("Parcourrir une image"); bouton.setBounds(50,250,400,30); bouton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Stub de la méthode généré automatiquement //chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//permet de sectionner un dossier chooser.showOpenDialog(null); FileNameExtensionFilter filtre=new FileNameExtensionFilter("IMAGE", "gif","png","jpg");//Permet de filtrer les extensions choisi chooser.addChoosableFileFilter(filtre); //chooser.setCurrentDirectory(new File("/home/linux/Bureau/EXAMEN/MERISE_CISSE")); int result=chooser.showSaveDialog(null); if (result==chooser.APPROVE_OPTION) { File imgchoisi=chooser.getSelectedFile(); String path=imgchoisi.getAbsolutePath(); ImageIcon mon_image=new ImageIcon(path); System.out.println(path); java.awt.Image img=mon_image.getImage(); java.awt.Image imageretrecit=img.getScaledInstance(labelimg.getWidth(), labelimg.getHeight(), java.awt.Image.SCALE_SMOOTH); ImageIcon imagefinal=new ImageIcon(imageretrecit); labelimg.setIcon(imagefinal); blob=path; } else if(result==chooser.CANCEL_OPTION){ System.out.println("Ta rien choisi"); } } }); this.add(bouton); } private void ajout_blob() { } public static void main(String[] args) { try { UIManager.setLookAndFeel("com.jtattoo.plaf.luna.LunaLookAndFeel"); } catch (Exception e) { // TODO: handle exception } Loading n_objet = new Loading(); n_objet.setVisible(true); } }