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

JDBC Java Discussion :

unreported exception: java.lang.ClassNotFoundException


Sujet :

JDBC Java

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2005
    Messages
    74
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2005
    Messages : 74
    Par défaut unreported exception: java.lang.ClassNotFoundException
    hello
    voici l'erreur apres execution du code qui va suivre
    unreported exception: java.lang.ClassNotFoundException; must be caugth or declared to be thown

    voici mon code

    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
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
    import java.net.*;
    import java.util.*;
    import java.sql.*;
    public class connectiondb{ 
     
    	Connection conn = null; 
            Statement S=null;
            ResultSet RS=null;
     public connectiondb(String cf,String df,String phf)
     {cf=null;df=null;phf=null;};   
     public void connectiondb() throws ClassNotFoundException{
     
             String strClassName = "sun.jdbc.odbc.JdbcOdbcDriver";
             String strUrl = "jdbc:odbc:BD_Incidents";
             Class.forName(strClassName);
             String username="sa";
             String password="sa";
     
              //username=nom utilisateur
               //password=mot de passe
                   try {
             conn = DriverManager.getConnection(strUrl,"",""); 
          }
           catch(Exception  e){
             //System.err.println("Driver non chargé !");
             e.printStackTrace();  
           }
       }
     public void insertion_filiale(String cf, String df, String phf){
         try{	 String sql="insert into filiale values('"+cf+" 
    ','"+df+"','"+phf+"')";
                     int Ligne;
                     S=conn.createStatement();
                     Ligne=S.executeUpdate(sql);
        	}catch(Exception e){
    		System.out.println("erreur lors connection bd("+e+")");
    	}
     
     }
     public void selection_filiale(String cf, String df, String phf){
         try{	 
                     String sql="select * from filiale";
                     S=conn.createStatement();
                     RS=S.executeQuery(sql);
                     int nlig=RS.getMetaData().getColumnCount();
                     while(RS.next()){
                         cf=RS.getString(1);
                         df=RS.getString(2);
                         phf=RS.getString(3);
                     }
        	}catch(Exception e){
    		//System.out.println("erreur lors connection bd("+e+")");
    	}
     
     }
    et voici l'appel dans JFfiliale()
    [code]
    connectiondb con=new connectiondb();
    con.connectiondb();
    con.insertion_filiale(cf,df,phf);
    con.selection_filiale(cf,df,phf);

  2. #2
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Août 2002
    Messages
    237
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Meurthe et Moselle (Lorraine)

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

    Informations forums :
    Inscription : Août 2002
    Messages : 237
    Par défaut
    Oui car quand tu écris ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    public void connectiondb() throws ClassNotFoundException
    Tu lui indiques que la méthode appelante doit gérer l'erreur renvoyée, donc :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    try{
    connectiondb con=new connectiondb();
    con.connectiondb();
    con.insertion_filiale(cf,df,phf);
    con.selection_filiale(cf,df,phf);
    }catch(ClassNotFoundException ex){
    // Traitement de l'erreur
    }
    J'imagine que tu as du avoir l'erreur à la compilation...

    Le throws veut dire : je ne gère pas les exceptions mais les renvoie à la méthode appelante.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 19/12/2014, 00h05
  2. Réponses: 1
    Dernier message: 07/08/2012, 12h10
  3. Réponses: 2
    Dernier message: 09/11/2010, 02h12
  4. Resoudre exception java.lang,OutOfMemory
    Par Battosaiii dans le forum Langage
    Réponses: 9
    Dernier message: 02/08/2006, 17h04
  5. java.lang.ClassNotFoundException
    Par au_record dans le forum JBuilder
    Réponses: 1
    Dernier message: 30/04/2006, 20h26

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