oceane751 Profil : Jeune recrue | je te mets tout mon code :
Code :
- package com.champstexte.test;
- import java.awt.event.*;
- import java.sql.*;
- import java.awt.*;
- import javax.swing.JOptionPane;
- /**
- * <p>Titre : </p>
- * <p>Description : </p>
- * <p>Copyright : Copyright (c) 2005</p>
- * <p>Société : </p>
- * @author non attribuable
- * @version 1.0
- */
- public class ChampsTexte extends Frame implements ActionListener
- {
- static public void main(String argv[]) {
- new ChampsTexte();
- }
- public ChampsTexte() {
- TextField prenom = new TextField("Votre prénom", 20);
- Label message = new Label();
- prenom.addActionListener(this);
- prenom.selectAll(); // pour sélectionner le texte du champ
- add(prenom);
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == prenom) {
- 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 = prenom.getText()" );
- 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);
- }
- }
- }
- }
- }
|
je vais essayer ce que tu m'a donner, mais j'aimerais comprendre pourquoi il y a cette erreur...
|