IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques en Java Discussion :

Probl�me de gestion des exceptions avec l'interface graphique


Sujet :

Interfaces Graphiques en Java

  1. #1
    Membre confirm�
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2011
    Messages
    181
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Mai 2011
    Messages : 181
    Par d�faut Probl�me de gestion des exceptions avec l'interface graphique
    Bonsoir,

    J'ai une Frame qui permet d�ins�rer un soignant et, j'ai une classe ou j'ai une m�thode qui permet d�ins�rer dans ma base de donn�e un nouveau soignant. Comment je pourrais afficher un message dans mon Frame selon ma m�thode,si il a bien �tait ajouter un message informatif ou un message erreur si une erreur a �t� catch

    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
    public void ajouterSoignant(int numSoignant, String nomSoignant, String prenomSoignant, String specialite,
    			String loginSoignant, String passSoignant) {
    		String sql = "insert into SOIGNANT (NUMSOIGNANT,NOMSOIGNANT,PRENOMSOIGNANT,SPECIALITE,LOGINSOIGNANT,PASSSOIGNANT) values(?,?,?,?,?,?)";
    		try {
    			PreparedStatement stmt = conn.prepareStatement(sql);
    			stmt.setInt(1, numSoignant);
    			stmt.setString(2, nomSoignant);
    			stmt.setString(3, prenomSoignant);
    			stmt.setString(4, specialite);
    			stmt.setString(5, loginSoignant);
    			stmt.setString(6, passSoignant);
    			stmt.executeUpdate();
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    	}
    public void actionPerformed(ActionEvent arg0) {
     
    				soignant.ajouterSoignant(Integer.parseInt(textNum.getText()), textNom.getText(), textPrenom.getText(),
    						(String) (comboSpecialite.getSelectedItem()), textLogin.getText(), textPass.getText());
    }
    Merci d'avance

  2. #2
    Membre confirm�
    Homme Profil pro
    �tudiant
    Inscrit en
    Mai 2011
    Messages
    181
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activit� : �tudiant

    Informations forums :
    Inscription : Mai 2011
    Messages : 181
    Par d�faut
    J'ai cherch� et j'ai r�ussi � faire et je souhaite savoir si c'est correct
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    public class BaseDonneeException extends SQLException{
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 1L;
     
    	public BaseDonneeException(String message)
    	{
    		super(message);
    	}
    }
    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
     
    public void ajouterSoignant(int numSoignant, String nomSoignant, String prenomSoignant, String specialite,
    			String loginSoignant, String passSoignant) throws BaseDonneeException {
     
    		String sql = "insert into SOIGNANT (NUMSOIGNANT,NOMSOIGNANT,PRENOMSOIGNANT,SPECIALITE,LOGINSOIGNANT,PASSSOIGNANT) values(?,?,?,?,?,?)";
     
     
    			PreparedStatement stmt;
    			try {
    				stmt = conn.prepareStatement(sql);
    				stmt.setInt(1, numSoignant);
    				stmt.setString(2, nomSoignant);
    				stmt.setString(3, prenomSoignant);
    				stmt.setString(4, specialite);
    				stmt.setString(5, loginSoignant);
    				stmt.setString(6, passSoignant);
    				stmt.executeUpdate();
    			} catch (Exception e) {
     
    				throw new BaseDonneeException("un problème est survenu lors de l'ajout");
    			}
    	}
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public void actionPerformed(ActionEvent arg0) {
     
    				try {
    					soignant.ajouterSoignant(Integer.parseInt(textNum.getText()), textNom.getText(), textPrenom.getText(),
    							(String) (comboSpecialite.getSelectedItem()), textLogin.getText(), new String(textPass.getPassword()));
    					JOptionPane.showMessageDialog(null, "ajouter avec succés","information",JOptionPane.INFORMATION_MESSAGE);
     
    				} catch (BaseDonneeException e) {
    					JOptionPane.showMessageDialog(null, e.getMessage(),"Erreur",JOptionPane.ERROR_MESSAGE);
    				}

  3. #3
    Membre exp�riment�
    Avatar de anadoncamille
    Homme Profil pro
    Ing�nieur d�veloppement logiciels
    Inscrit en
    Juillet 2007
    Messages
    395
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyr�n�es)

    Informations professionnelles :
    Activit� : Ing�nieur d�veloppement logiciels
    Secteur : High Tech - �diteur de logiciels

    Informations forums :
    Inscription : Juillet 2007
    Messages : 395
    Billets dans le blog
    1
    Par d�faut
    De prime abord, ton code semble correct. Ton application fonctionne-t-elle comme tu veux ?

Discussions similaires

  1. [POO] Gestion des exception avec php4
    Par mulot49 dans le forum Langage
    R�ponses: 1
    Dernier message: 26/04/2007, 10h18
  2. Probl�me de gestion des exceptions
    Par Artasali dans le forum C++Builder
    R�ponses: 2
    Dernier message: 08/02/2007, 03h20
  3. R�ponses: 2
    Dernier message: 01/12/2006, 19h55
  4. Probl�me de gestion des langues avec MFC
    Par Figaro dans le forum Visual C++
    R�ponses: 4
    Dernier message: 20/11/2006, 15h56
  5. [vb.net]Gestion des exceptions avec les web services
    Par mvr dans le forum Windows Forms
    R�ponses: 2
    Dernier message: 05/12/2005, 22h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo