Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpackage com.chercher.test; import javax.swing.*; import java.awt.event.*; import java.sql.*; import javax.swing.JOptionPane; public class Chercher extends JFrame { public Chercher() { super("chercher"); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; //addWindowListener(l); class Interface implements ActionListener { ImageIcon img = new ImageIcon("rechercher.gif"); JButton boutton = new JButton("Chercher", img); JPanel pan = new JPanel(); JTextField text = new JTextField("nom client", 15); boutton.addActionListener(new ActionListener(this)); //panneau.add(text); pan.add(boutton); pan.setContentPane(panneau); pan.setSize(200,150); pan.setVisible(true); } } public void actionPerfomed(ActionEvent e) { if(e.getSource() == boutton) { Connection con = null; Statement instruction = null; ResultSet resultat = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql:///bd_info","root",""); instruction = con.createStatement(); resultat instruction.executeQuery("SELECT designation_produit,type_produit FROM produit WHERE ref_produit 5"); String produit = ""; String produit2 =""; while(resultat.next()) { produit += resultat.getString("designation_produit") +""; produit2 += resultat.getString("type_produit") +""; } JOptionPane.showMessageDialog(null, "Produit : " + produit + "type : " + produit2 + "\u20ac"); } catch(ClassNotFoundException ex) { JOptionPane.showMessageDialog(null, "Classe introuvable" + ex.getMessage()); } catch(SQLException ex) { JOptionPane.showMessageDialog(null, "erreur JDBC : " + ex.getMessage()); } finally { try { if (resultat != null) resultat.close(); if (con != null) con.close(); } catch (SQLException ex) { ex.printStackTrace(); } } System.exit(0); } } public static void main(String [] args){ JFrame frame = new Chercher(); } }
package com.chercher.test; import javax.swing.*; import java.awt.event.*; import java.sql.*; import javax.swing.JOptionPane; public class Chercher extends JFrame implements ActionListener { public Chercher() { super("chercher"); ImageIcon img = new ImageIcon("rechercher.gif"); JButton boutton = new JButton("Chercher", img); boutton.addActionListener(this); JPanel pan = new JPanel(); JTextField text = new JTextField("nom client", 15); pan.add(boutton); getContentPane().add(pan); //getContenPane().add(pan, BorderLayout.NORTH); pan.add(text); pan.add(boutton); setContentPane(pan); setSize(200, 150); setVisible(true); } WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); addWindowListener(l); } public void actionPerfomed(ActionEvent e) { if (e.getSource() == boutton) { Connection con = null; Statement instruction = null; ResultSet resultat = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql:///bd_info", "root", ""); instruction = con.createStatement(); resultat = instruction.executeQuery( "SELECT designation_produit,type_produit FROM produit WHERE ref_produit = 5"); String produit = ""; String produit2 = ""; while (resultat.next()) { produit += resultat.getString("designation_produit") + ""; produit2 += resultat.getString("type_produit") + ""; } JOptionPane.showMessageDialog(null, "Produit : " + produit + "type : " + produit2 + "\u20ac"); } catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(null, "Classe introuvable" + ex.getMessage()); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "erreur JDBC : " + ex.getMessage()); } finally { try { if (resultat != null) resultat.close(); if (con != null) con.close(); } catch (SQLException ex) { ex.printStackTrace(); System.exit(0); } } }} public static void main(String[] args) { JFrame frame = new Chercher(); }} ==> le dernier crochet est en rouge et je ne vois pas pourquoi :s