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

NetBeans Java Discussion :

Initaliser Jlist/ Postgres


Sujet :

NetBeans Java

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 18
    Points : 15
    Points
    15
    Par défaut Initaliser Jlist/ Postgres
    Bonjour,

    Comme dit dans le titre, je n'arrive pas à initialiser une Jlist créée grâce à l'interface("ListDossierEnCours"), j'ai essayé plusieurs méthodes..Mais rien n'y fait!
    Voilà le dernier essai que j'ai mis au point:

    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
     
    import java.sql.Connection;
    import java.sql.Date;
    import static java.sql.Date.valueOf;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import javax.swing.DefaultListModel;
    import javax.swing.JList;
    public class Model extends ArrayList{
          private Connection connection = null;
          public void establishConnection()
        {
            if (connection != null)
                return;
            String url = "jdbc:postgresql://localhost:5432/clairance";
            try
            {
               Class.forName("org.postgresql.Driver");
               System.out.println("driver OK");
               connection = DriverManager.getConnection(url, "nadi", "*pass");
     
               if (connection != null) {
                   System.out.println("Connecting to database...");
               }
            } catch(Exception e){
                System.out.println("Problem when connecting to the database 1");
            }
        }
          public  ArrayList FillList(ArrayList list){
        ResultSet rs = null;
        Statement s = null;
         String nomPatient;
         String dateExamen;    
         String NomElementListe;
          Date myDate;
           try
            {   s = connection.createStatement();
                  rs = s.executeQuery("SELECT patient.nom, dateexamen from examen, patient where examen.Est_valide = false;");     
    while (rs.next()) {
     nomPatient = rs.getString("nom");
       dateExamen = rs.getString("dateexamen");
       myDate = valueOf(dateExamen);
        NomElementListe ="Examen de "+nomPatient+ "effectuée le"+ myDate;
        list.add(NomElementListe);
       //theList = new JList(listModel);
                                        }  
            }     
    catch (Exception e)
            {
                System.out.println("Problema lista ");
            }  
    return (list);
    }}

    Dans le main :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    Model model = new Model();
      model.establishConnection();
      ArrayList AR = new ArrayList();
      AR= model.FillList(AR);
      for (int i =0; i>= AR.size(); i++){
      PF.ListDossierEnCours.add(AR.get(i));

    Je m'en remet aux maîtres de la connaissance Java : est ce que vous pouvez m'aidez svp? Merci beaucoup.

  2. #2
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2013
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2013
    Messages : 18
    Points : 15
    Points
    15
    Par défaut J'ai trouvé!
    C'est bon...mon honneur est sauf (si je puis dire)...
    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    import java.sql.Connection;
    import java.sql.Date;
    import static java.sql.Date.valueOf;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.ArrayList;
    import javax.swing.DefaultListModel;
    import javax.swing.JList;
     
    /**
     *
     */
    public class Model extends DefaultListModel{
          private Connection connection = null;
          public void establishConnection()
        {
            if (connection != null)
                return;
            String url = "jdbc:postgresql://localhost:5432/clairance";
            try
            {
               Class.forName("org.postgresql.Driver");
               System.out.println("driver OK");
               connection = DriverManager.getConnection(url, "nadi", "*pass");
     
               if (connection != null) {
                   System.out.println("Connecting to database...");
               }
            } catch(Exception e){
                System.out.println("Problem when connecting to the database 1");
            }
        }
    //    public  DefaultListModel FillList(){
     //   ResultSet rs = null;
     //   Statement s = null;
     //    String nomPatient;
     //    String dateExamen;    
      //   String NomElementListe;
      //    Date myDate;
       //    DefaultListModel listModel = new DefaultListModel();
           //JList list = null; 
       //    try
         //   {   s = connection.createStatement();
           //       rs = s.executeQuery("SELECT patient.nom, dateexamen from examen, patient where examen.Est_valide = false;");     
    //while (rs.next()) {
    // nomPatient = rs.getString("nom");
     //System.out.println(nomPatient);
       //dateExamen = rs.getString("dateexamen");
        //System.out.println(dateExamen);
       //myDate = valueOf(dateExamen);
       // NomElementListe ="Examen de "+nomPatient+ "effectuée le"+ myDate;
        //listModel.addElement(NomElementListe);
       //theList = new JList(listModel);
            //                            }  
          //  }     
    //catch (Exception e)
      //      {
        //        System.out.println("Problema lista ");
          //  }  
    //return (listModel);
     
    //}
         /** 
          public  ArrayList FillList(ArrayList list){
        ResultSet rs = null;
        Statement s = null;
         String nomPatient;
         String dateExamen;    
         String NomElementListe;
          Date myDate;
       // ArrayList list = new ArrayList();
          //DefaultListModel listModel = new DefaultListModel();
           //JList list = null; 
           try
            {   s = connection.createStatement();
                  rs = s.executeQuery("SELECT patient.nom, dateexamen from examen, patient where examen.Est_valide = false;");     
    while (rs.next()) {
     nomPatient = rs.getString("nom");
     System.out.println(nomPatient);
       dateExamen = rs.getString("dateexamen");
        System.out.println(dateExamen);
       myDate = valueOf(dateExamen);
        NomElementListe ="Examen de "+nomPatient+ "effectuée le"+ myDate;
        list.add(NomElementListe);
       //theList = new JList(listModel);
                                        }  
            }     
    catch (Exception e)
            {
                System.out.println("Problema lista ");
            }  
    return (list);
          }
          
          */
         public DefaultListModel fillList() {
     
         ResultSet rs = null;
        Statement s = null;
         String nomPatient;
         String dateExamen;      
          Date myDate;          
       String NomElementListe = null;
           //int i=1;
          DefaultListModel DLM = null;
           try{
           s = connection.createStatement();
           rs = s.executeQuery("SELECT patient.nom, dateexamen from examen, patient where examen.Est_valide = false;");     
           while (rs.next()) {
                nomPatient = rs.getString("nom");
                System.out.println(nomPatient);
                dateExamen = rs.getString("dateexamen");
                System.out.println(dateExamen);
              //  myDate = valueOf(dateExamen);
                NomElementListe ="Examen de " +nomPatient+ " effectué le "+ dateExamen;
                System.out.println(NomElementListe);
                DLM = new DefaultListModel();
                DLM.addElement(NomElementListe);
     
     
    // list.add(NomElementListe);
       //theList = new JList(listModel);
     
     
                                }
     
           }
     catch(Exception e)  {
             System.out.println("problema");
             }
     
         return (DLM);
     
         }
     
     
    }
    Aux modérateurs: Je sais pas si c'est intéressant de garder cette discussion ...
    Merci quand même! (ce forum est génial...actuellement, en train de faire un projet java...ça m'aide beaucoup!! ^^)

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

Discussions similaires

  1. [PostgreSQL/CYGWIN] install de postgres sous WINdows
    Par loicmillion dans le forum Administration
    Réponses: 2
    Dernier message: 16/04/2003, 11h37
  2. [Class/PHP/Postgres] Problème de modélisation...
    Par k-reen dans le forum PostgreSQL
    Réponses: 4
    Dernier message: 27/02/2003, 08h49
  3. pk passer de mysql à postgre
    Par pioums dans le forum Autres SGBD
    Réponses: 2
    Dernier message: 03/10/2002, 10h31
  4. [Kylix] Requetes Kylix pour postgres
    Par Miltown dans le forum EDI
    Réponses: 1
    Dernier message: 29/05/2002, 20h22
  5. [Kylix] Kylix - Postgres
    Par Miltown dans le forum EDI
    Réponses: 1
    Dernier message: 29/05/2002, 20h19

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