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

API standards et tierces Java Discussion :

probléme de connexion à une base mysql


Sujet :

API standards et tierces Java

  1. #1
    Membre à l'essai
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Points : 24
    Points
    24
    Par défaut probléme de connexion à une base mysql
    salut j'ai un probléme au niveau de connexion a la base de donnée avec mysql
    voila erreur
    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
    Opening db connection
    Cannot connect to this database.
    java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
    Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: No Persistence provider for EntityManager named miniprojetPU
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:56)
    	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    	at Frames.GestionUtilisateur.initComponents(GestionUtilisateur.java:59)
    	at Frames.GestionUtilisateur.<init>(GestionUtilisateur.java:33)
    	at Frames.Accueil$1.run(Accueil.java:94)
    	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
    	at java.awt.EventQueue.access$200(EventQueue.java:103)
    	at java.awt.EventQueue$3.run(EventQueue.java:682)
    	at java.awt.EventQueue$3.run(EventQueue.java:680)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    	at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    	at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

  2. #2
    vinou92340
    Invité(e)
    Par défaut
    Tu es sur que tu n'as pas de mot de passe ?
    Pourrais tu indiquer l'url de connexion à la base ?

  3. #3
    Membre à l'essai
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Points : 24
    Points
    24
    Par défaut
    Citation Envoyé par vinou92340 Voir le message
    Tu es sur que tu n'as pas de mot de passe ?
    Pourrais tu indiquer l'url de connexion à la base ?
    voila la class connection
    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.util.Vector;
    import java.sql.*;
    import javax.swing.table.AbstractTableModel;
    public class MyConnection extends AbstractTableModel
    {
        private static MyConnection jdbcAdapter;
        private static Connection connection =null;
       private static Statement statement;
       private static ResultSet resultSet;
      private static  String[] columnNames = {};
       private static Vector rows = new Vector();
       private static ResultSetMetaData metaData;
     
        private MyConnection(String driverName, String url,
                String user, String passwd) {
            try {
     
     
                Class.forName(driverName);
                System.out.println("Opening db connection");
                connection = DriverManager.getConnection(url, user, passwd);
                //statement = connection.createStatement();
                statement = connection.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
     
            } catch (ClassNotFoundException ex) {
                System.err.println("Cannot find the database driver classes.");
                System.err.println(ex);
            } catch (SQLException ex) {
                System.err.println("Cannot connect to this database.");
                System.err.println(ex);
            }
        }
     
        private MyConnection() {
            try {
     
     
                Class.forName("com.mysql.jdbc.Driver");
                System.out.println("Opening db connection");
                connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/snmp", "root", "");
                //statement = connection.createStatement();
                statement = connection.createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
     
            } catch (ClassNotFoundException ex) {
                System.err.println("Cannot find the database driver classes.");
                System.err.println(ex);
            } catch (SQLException ex) {
                System.err.println("Cannot connect to this database.");
                System.err.println(ex);
            }
        }

  4. #4
    vinou92340
    Invité(e)
    Par défaut
    Moi je testerais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DriverManager.getConnection("jdbc:mysql://localhost:3306/snmp?user=root&password=")
    Ou sinon :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/snmp?user=root&password=")
    Mais bon, chose étrange, il semblerait que cela vienne plutôt d'un problème de user/mdp. Es tu sur de ton user et qu'il n'y a pas de password ?

  5. #5
    Membre à l'essai
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Points : 24
    Points
    24
    Par défaut
    Citation Envoyé par vinou92340 Voir le message
    Moi je testerais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DriverManager.getConnection("jdbc:mysql://localhost:3306/snmp?user=root&password=")
    Ou sinon :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/snmp?user=root&password=")
    Mais bon, chose étrange, il semblerait que cela vienne plutôt d'un problème de user/mdp. Es tu sur de ton user et qu'il n'y a pas de password ?
    dans la base il y a une table utlisateur contient login et mp et j'ai mis dans login root et dans mp vide

  6. #6
    vinou92340
    Invité(e)
    Par défaut
    Et pour accéder à toutes tes bases de données, tes tables via une interface du genre mysqlworkbench, tu ne rentres pas un user et un mot de passe ?

  7. #7
    Membre à l'essai
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Points : 24
    Points
    24
    Par défaut
    Citation Envoyé par vinou92340 Voir le message
    Et pour accéder à toutes tes bases de données, tes tables via une interface du genre mysqlworkbench, tu ne rentres pas un user et un mot de passe ?
    oui c'est root root

  8. #8
    vinou92340
    Invité(e)
    Par défaut
    Alors testes avec root root ^^.

  9. #9
    Membre émérite
    Avatar de olivier.pitton
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2012
    Messages
    355
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Hauts de Seine (Île de France)

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

    Informations forums :
    Inscription : Juin 2012
    Messages : 355
    Points : 2 814
    Points
    2 814
    Par défaut
    Plop,

    Je pense que le problème ne vient pas de ta connexion mais du fait que tu utilises des APIs différentes. Ton erreur indique que tu veux utiliser JPA et son EntityManager (et les packages javax.persistence dans la stacktrace) alors que ton code indique que tu utilises JDBC.

    Si tu regardes la stacktrace, l'erreur ne provient pas de la classe Connexion, mais de GestionUtilisateur.

    Si tu veux utiliser JPA, tu dois définir un PersistenceProvider (dans le fichier META-INF/persistence.xml), sinon tu utilises JDBC. Mais toi, tu utilises les deux avec le premier mal configuré.

    Enlève tout ce qui est relatif à JPA (javax.persistence) ou tout ce qui est relatif à JDBC.

    Je pense qu'il s'agit plutôt de cela, ou alors que tu n'as pas lancé ton MySQL.

  10. #10
    vinou92340
    Invité(e)
    Par défaut
    Arf, cela ne serait-il pas un autre type d'erreur dans ce cas là ?

  11. #11
    Membre à l'essai
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Points : 24
    Points
    24
    Par défaut
    j'ai résolu un peu le probléme avec la connexion a la base de donnée mais dans la class snmp il m'affiche des exceptions lors de récupération de données du pc
    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
    connexion etablie
    **************** Information pc:0*********************
    connexion etablie
    janv. 01, 2013 11:50:50 AM mini.projet.GWI.ScanNetworkInterface$5 run
    SEVERE: null
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'info' at row 1
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3607)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:842)
    	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:681)
    	at mini.projet.GWI.ScanNetworkInterface$5.run(ScanNetworkInterface.java:316)
    voila la class scan
    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
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    /*
     * ScanNetworkInterface.java
     *
     * Created on 15 juin 2012, 17:05:33
     */
     
    package mini.projet.GWI;
    import mini.projet.dao.ScanNetwork;
    import mini.projet.base.MyConnection;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Date;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JDialog;
    import javax.swing.JOptionPane;
    /**
     *
     * @author mohsen
     */
    public class ScanNetworkInterface extends javax.swing.JFrame {
     
        /** Creates new form ScanNetworkInterface */
         Connection con;
    static  Statement st;
     Connection con1;
    static  Statement st1;
     //Thread t;
        public ScanNetworkInterface() {
     
            try {
                     Class.forName("org.gjt.mm.mysql.Driver");
     
                    } catch (Exception E) {
                        System.out.println("Pas de pilote !");
                    }
                            try {
                    String url = "jdbc:mysql://localhost:3306/firstdao";
                    con = DriverManager.getConnection(url, "root", "root");
                                System.out.println("connexion etablie");
                       st = con.createStatement();
                } catch (SQLException E) {
                    System.err.println(E.getMessage());
                }
            initComponents();
     
            Thread tThread=new Thread(){
                public void run(){
                    while(true){
                        try {
                int i=0;
                ResultSet ts = st.executeQuery("select * from find");
     
                while(ts.next())
                {
                       jTable1.setValueAt(ts.getString(1), i, 0);
                       jTable1.setValueAt(ts.getString(2), i, 1);
                       jTable1.setValueAt(ts.getString(3), i, 2);
                       jTable1.setValueAt(ts.getString(4), i, 3);
     
                       i++;
                }
     
     
            } catch (SQLException ex) {
                Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
                    }
                }
            };
            tThread.start();
        }
     
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jButton1 = new javax.swing.JButton();
            jLabel1 = new javax.swing.JLabel();
            jScrollPane2 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jLabel2 = new javax.swing.JLabel();
            jTextField1 = new javax.swing.JTextField();
            jLabel3 = new javax.swing.JLabel();
            jTextField2 = new javax.swing.JTextField();
            jLabel4 = new javax.swing.JLabel();
            jTextField3 = new javax.swing.JTextField();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Interface de scan");
     
            jTextArea1.setColumns(20);
            jTextArea1.setRows(5);
            jScrollPane1.setViewportView(jTextArea1);
     
            jButton1.setText("Lancer scan");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
     
            jLabel1.setText("Opérations en cours:");
     
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                },
                new String [] {
                    "Nom", "Hardware", "Disque", "Memoire"
                }
            ) {
                boolean[] canEdit = new boolean [] {
                    false, false, false, false
                };
     
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
                }
            });
            jScrollPane2.setViewportView(jTable1);
     
            jLabel2.setText("16 premier bits: exp(192.168.)");
     
            jLabel3.setText("Debut");
     
            jTextField2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField2ActionPerformed(evt);
                }
            });
     
            jLabel4.setText("Fin");
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jButton1)
                            .addGap(28, 28, 28))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 784, Short.MAX_VALUE)
                            .addContainerGap())
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(642, Short.MAX_VALUE))))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addComponent(jLabel2)
                            .addGap(26, 26, 26)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(42, 42, 42)
                            .addComponent(jLabel3)
                            .addGap(31, 31, 31)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jLabel4)
                            .addGap(31, 31, 31)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(47, 47, 47)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 601, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap())
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(29, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(28, 28, 28)
                    .addComponent(jLabel1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButton1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap())
            );
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
     
            pack();
        }// </editor-fold>
     
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
           Thread t=new Thread(){
                public void run(){
                    jButton1.setEnabled(false);
                  /*  ScanNetwork a=new ScanNetwork();
          StringBuffer gg =new StringBuffer();
         int k=0;
                gg.append(""+jTextField1.getText());
                //int tBit=Integer.parseInt(jTextField2.getText());
               // int qBit=Integer.parseInt(jTextField3.getText());
                for(int j=200;j<256;j++)
                for(int i=255;i<255;i++)
                {
                    if (a.getRequest(gg.toString()+j+"."+i,"1.3.6.1.2.1.1.1.0")== ""){
                        jTextArea1.append(gg.toString()+j+"."+i+"\n");
                   }
                    else
                    {
     
                      System.out.println("**************** Information pc:"+k+"*********************");
                      String nom=a.getRequest(gg.toString()+j+"."+i,"1.3.6.1.2.1.1.5.0");
                            jTextArea1.append(nom+"\n");
                        String hard=a.getRequest(gg.toString()+j+"."+i,"1.3.6.1.2.1.1.1.0");
                        String dis="",mem="";
                         for(int x=1; x<6;x++)
                            dis+=a.getRequest(gg.toString()+j+"."+i, "1.3.6.1.2.1.25.2.3.1.3."+x)+"   ";
                        for(int y=4; y<5;y++)
                            mem+=a.getRequest(gg.toString()+j+"."+i, "1.3.6.1.2.1.25.2.3.1."+y+".1")+"   ";
     
                         try {
                st.execute("INSERT INTO `snmp`.`find` (`nom`,`info`, `disque`, `memoire`) VALUES ('"+
                        nom+"', '"+hard+"', '"+dis+"', '"+mem+"');");
            } catch (SQLException ex) {
                Logger.getLogger(ConIdentification.class.getName()).log(Level.SEVERE, null, ex);
            }
     
                        k++;
                    }
     
                }
                jButton1.setEnabled(true);*/
                    jTextArea1.setText("");
                     ScanNetwork a=new ScanNetwork();
          StringBuffer gg =new StringBuffer();
         int k=0;
                gg.append(jTextField1.getText());
                int tBit=Integer.parseInt(jTextField2.getText());
                int qBit=Integer.parseInt(jTextField3.getText());
                for(int j=tBit;j<256;j++)
                for(int i=qBit;i<255;i++)
                {
                    if (a.getRequest(gg.toString()+j+"."+i,"1.3.6.1.2.1.1.1.0")== ""){
                        jTextArea1.append(gg.toString()+j+"."+i+"\n");
                   }
                    else
                    {
                      System.out.println("**************** Information pc:"+k+"*********************");
                      String nom=a.getRequest(gg.toString()+j+"."+i,"1.3.6.1.2.1.1.5.0");
                            jTextArea1.append(nom+"\n");
                        String hard=a.getRequest(gg.toString()+j+"."+i,"1.3.6.1.2.1.1.1.0");
                        String dis="",mem="";
                         for(int x=1; x<6;x++)
                            dis+=a.getRequest(gg.toString()+j+"."+i, "1.3.6.1.2.1.25.2.3.1.3."+x)+"\n";
                        for(int y=4; y<5;y++)
                            mem+=a.getRequest(gg.toString()+j+"."+i, "1.3.6.1.2.1.25.2.3.1."+y+".1")+"\n";
     
                        try {
                     Class.forName("org.gjt.mm.mysql.Driver");
     
                    } catch (Exception E) {
                        System.out.println("Pas de pilote !");
                    }
                            try {
                    String url = "jdbc:mysql://localhost:3306/firstdao";
                    con1 = DriverManager.getConnection(url, "root", "root");
                                System.out.println("connexion etablie");
                       st1 = con1.createStatement();
                } catch (SQLException E) {
                    System.err.println(E.getMessage());
                }
                        if(findah(nom))
                          try {
                st1.execute("INSERT INTO `firstdao`.`find` (`nom`,`info`, `disque`, `memoire`) VALUES ('"+
                        nom+"', '"+hard+"', '"+dis+"', '"+mem+"');");
            } catch (SQLException ex) {
                Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
                      k++;
                    }
     
                }
                jTextArea1.append("Terminé!");
                jButton1.setEnabled(true);
                }
            };
            t.start();
        }                                        
     
        private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // TODO add your handling code here:
        }                                           
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
     
                    new ScanNetworkInterface().setVisible(true);
     
     
        }
     
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JScrollPane jScrollPane2;
        private javax.swing.JTable jTable1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        // End of variables declaration
     
        public boolean findah(String nom){
            boolean result=true;
            try {
                ResultSet ts = st1.executeQuery("select * from auth");
                while(ts.next())
                {
                    String ident=ts.getString(1);
     
     
                   if((nom.equals(ident)))
                   {
                        result=false;
                   }
     
                }
            } catch (SQLException ex) {
                Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
            }
            return result;
        }
    }

  12. #12
    Modérateur

    Homme Profil pro
    Développeur java, access, sql server
    Inscrit en
    Octobre 2005
    Messages
    2 711
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Développeur java, access, sql server
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2005
    Messages : 2 711
    Points : 4 796
    Points
    4 796
    Par défaut
    Ben là c'est assez clair :
    at mini.projet.GWI.ScanNetworkInterface$5.run(ScanNetworkInterface.java:316)
    ce n'est pas une récupération de données mais une insertion dans la base à la ligne 316 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
                st1.execute("INSERT INTO `firstdao`.`find` (`nom`,`info`, `disque`, `memoire`) VALUES ('"+
                        nom+"', '"+hard+"', '"+dis+"', '"+mem+"');");
    Data too long for column 'info'
    donc le contenu de la variable hard est trop long pour le champ
    Labor improbus omnia vincit un travail acharné vient à bout de tout - Ambroise Paré (1510-1590)

    Consulter sans modération la FAQ ainsi que les bons ouvrages : http://jmdoudoux.developpez.com/cours/developpons/java/

  13. #13
    Membre à l'essai
    Inscrit en
    Mars 2011
    Messages
    230
    Détails du profil
    Informations forums :
    Inscription : Mars 2011
    Messages : 230
    Points : 24
    Points
    24
    Par défaut
    Citation Envoyé par Népomucène Voir le message
    Ben là c'est assez clair :

    ce n'est pas une récupération de données mais une insertion dans la base à la ligne 316 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
                st1.execute("INSERT INTO `firstdao`.`find` (`nom`,`info`, `disque`, `memoire`) VALUES ('"+
                        nom+"', '"+hard+"', '"+dis+"', '"+mem+"');");
    donc le contenu de la variable hard est trop long pour le champ
    c'est résolu ça marche bien merci

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

Discussions similaires

  1. probléme de connexion à une base mysql
    Par zied_m dans le forum Accès aux données
    Réponses: 0
    Dernier message: 09/07/2013, 16h31
  2. Problème de connexion à une base MySQL
    Par Jezlife dans le forum Bases de données
    Réponses: 5
    Dernier message: 06/12/2011, 11h17
  3. Problème de connexion à une base MySQL
    Par ctenot dans le forum NetBeans Platform
    Réponses: 8
    Dernier message: 23/11/2011, 03h59
  4. Réponses: 1
    Dernier message: 19/07/2007, 21h09
  5. Problème de connexion à une base de donnée MySQL
    Par casho dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 27/06/2007, 14h04

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