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 :

Exception Récuperé, pour affichage JTable lié a MySQL


Sujet :

JDBC Java

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 9
    Points : 6
    Points
    6
    Par défaut Exception Récuperé, pour affichage JTable lié a MySQL


    Voici l'exception Récupéré pour ce code-ci dessous
    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
     
    package FenetreTable;
     
    import java.awt.BorderLayout;
    import java.awt.Font;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Vector;
     
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JRootPane;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.DefaultTableModel;
     
    import Page.UtilsFenetre;
     
     
    	public class Drop extends JFrame{
    		 static DefaultTableModel tableDropModel;
    	     static JTable TableDrop;
    	     static ResultSet rsA;
    	     static Statement stmtA;
    	     static ResultSetMetaData rsMDA;
    	     static int colonnes;
    		public Drop( ){
    			setTitle( "Fenetre || Table : Drop" );
    			setSize( 500, 400 );
    			setResizable( false );
    			setUndecorated(true);
    		    setFocusableWindowState(true);
    			JRootPane rootPane = getRootPane();
    			rootPane.setWindowDecorationStyle(JRootPane.FRAME);
    			rootPane.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
    			JPanel PanDrop = new JPanel();
    			PanDrop.setLayout( new BorderLayout() );
    			getContentPane().add( PanDrop );
    			setVisible( true );
     
    			tableDropModel = new DefaultTableModel( );
    		    TableDrop = new JTable( tableDropModel ) {
     
    		         private static final long serialVersAionUID = 1L;
     
    		                public Class getColumnClass( int column ) {
     
    		                        return getValueAt( 0, column ).getClass( );
     
    		                        }
     
    		     };
     
    		     JScrollPane scrollPane = new JScrollPane( TableDrop );
    		     TableDrop.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
    		     PanDrop.add( scrollPane );    
     
     
    		      tableDropModel.addTableModelListener( new TableModelListener( ) {
     
    		          public void tableChanged( TableModelEvent evnt ) {
     
    		                updateDBRow( evnt );
     
    		           }
     
    		       });
     
     
    		                try {
     
    		                      Class.forName("com.mysql.jdbc.Driver");
    		                      Connection conn = DriverManager.getConnection("jdbc:mysql://" + UtilsFenetre.Host + "/" + UtilsFenetre.DB_STATIC, UtilsFenetre.User, UtilsFenetre.Pass );
     
    		                       stmtA = conn.createStatement( );
    		                       rsA = stmtA.executeQuery( "SELECT * FROM drops" );
     
    		                       rsMDA = rsA.getMetaData( );
    		                       colonnes = rsMDA.getColumnCount( );
     
     
    		                       Vector nomColonnes = new Vector( );
    		                       Vector data = new Vector( );       
     
    		                       for ( int i = 1; i <= colonnes; i++ ) { 
    		                       nomColonnes.addElement( rsMDA.getColumnName( i ) );
     
    		                       }
     
     
     
    		                       while ( rsA.next( ) ){
    		                              Vector row = new Vector( );
     
    		                        for (int i = 1; i <= colonnes; i++ ){
    		                              row.addElement( rsA.getObject( i ) );
    		                              }
    		                              data.addElement( row );
    		                        }
     
     
     
    		                        setTableData( data, nomColonnes );
    		                  }catch ( Exception ex ) { 
    		                	  JOptionPane.showMessageDialog( null, "Erreur : " + ex, "Attention", JOptionPane.ERROR_MESSAGE );} 
    		             }                     
    		      public static void setTableData( Vector d, Vector colname ) {
    		                  tableDropModel.setDataVector( d,colname );
    		      }
     
    		      public Class getColumnClass( int columnIndex ) {
    		                   return Boolean.class;
    		      }
     
    		      public static void updateDBRow( TableModelEvent evt ) {
     
    		           Object old = "";
     
    		           try {
     
    		                  if(evt.getType( ) == TableModelEvent.UPDATE && evt.getColumn( ) != -1 ){
    		                  rsA.absolute( evt.getFirstRow( )+1 );
    		                  rsA.getObject( evt.getColumn( )+1 );
    		                  rsA.updateObject( evt.getColumn( )+1,tableDropModel.getValueAt( evt.getFirstRow( ),evt.getColumn( ) ));
    		                  rsA.updateRow( );
     
    		                  }
     
    		           } catch (SQLException e) {JOptionPane.showMessageDialog( null,"Erreur"+e,"Attention",JOptionPane.ERROR_MESSAGE );
    		             tableDropModel.setValueAt( old,evt.getFirstRow( ),evt.getColumn( ));
    		           }
     
    		     }
    		}
    répéter une dizaine de fois...


    Comment evitez ce genre de problème ? Merci !


    HS : je savais pas trop où poster donc j'ai post ici

    EDIT : le code fonctionne que avec un .java comme ça,mais j'en ai une trentaine qui doit tous afficher le contenu de leurs tables,comment faire pour y remedier ?

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    il faudrait le stacktrace complet de l'exception pour pouvoir t'aider, on ne sais pas où dans ton code a lieu l'erreur.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 9
    Points : 6
    Points
    6
    Par défaut
    Le probleme,c'est que j'ai que ça !
    j'ai tester mon code a part,il fonctionne bien,mais avec les class que remplissent la même fonction pour une table differente ne fonctionne pas

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par Power-Java Voir le message
    Le probleme,c'est que j'ai que ça !
    Peut-être parce que tu n'affiche pas l'information utile:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    		                  }catch ( Exception ex ) { 
    		                	  JOptionPane.showMessageDialog( null, "Erreur : " + ex, "Attention", JOptionPane.ERROR_MESSAGE );}
    Juste le message d'erreur n'a aucune utilité, ce qui est important c'est où il a lieu dans le code, donc le stacktrace, que tu affiche avec


  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 9
    Points : 6
    Points
    6
    Par défaut
    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
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
     
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1119)
    	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2257)
    	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:784)
    	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:354)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at FenetreTable.Drop.<init>(Drop.java:79)
    	at Page.Sqlpage$1.valueChanged(Sqlpage.java:264)
    	at javax.swing.JTree.fireValueChanged(Unknown Source)
    	at javax.swing.JTree$TreeSelectionRedirector.valueChanged(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(Unknown Source)
    	at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(Unknown Source)
    	at javax.swing.JTree.setSelectionPath(Unknown Source)
    	at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(Unknown Source)
    	at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(Unknown Source)
    	at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
     
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    	at java.lang.reflect.Constructor.newInstance(Unknown Source)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1119)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)
    	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2178)
    	... 43 more
    Caused by: java.net.ConnectException: Connection refused: connect
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.PlainSocketImpl.doConnect(Unknown Source)
    	at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    	at java.net.PlainSocketImpl.connect(Unknown Source)
    	at java.net.SocksSocketImpl.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.<init>(Unknown Source)
    	at java.net.Socket.<init>(Unknown Source)
    	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
    	... 44 more
    Voici le StackTrace complet,comme tu me l'as demandé...
    Les "erreurs" pointent sur ces lignes là :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Connection conn = DriverManager.getConnection("jdbc:mysql://" + UtilsFenetre.Host + "/" + UtilsFenetre.DB_STATIC, UtilsFenetre.User, UtilsFenetre.Pass );
    et celle ci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    				FenetreTable.Drop Drop = new FenetreTable.Drop( );

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Caused by: java.net.ConnectException: Connection refused: connect
    Soit tu as mis le mauvais host et ça essaie de se connecter à un serveur qui n'a rien en fonctionnement sur le port mysql, soit tu as mis un mauvais numéro de port, soit le serveur auquel tu essaie de te connecter à distance est protégé par un firewall qui te bloque l'accès.

  7. #7
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 9
    Points : 6
    Points
    6
    Par défaut
    c'est du local,la Base de données MySql,est de chez moi...
    j'ai essayé en rentrant directement l'host tous ça,mais sa ne fonctionne pas...
    mon code fonctionne sans problème,mais tout seul...
    pas avec tout les .java qui font là même choses

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    mon code fonctionne sans problème,mais tout seul...
    pas avec tout les .java qui font là même choses
    La je comprend pas trop. Chaque composant utilise sa propre connection mysql? Tu n'aurais pas dépassé le nombre maximum de connections au serveur? En tout cas le message d'erreur est clair: la connection a été refusée par le serveur. Donc soit tu t'es trompé d'host (affiche la ligne de connection jdbc pour en être sur), soit celui-ci pour une raison x ou y (serveur à l'arrêt, serveur surchargé, etc) refuse les nouvelles connections.

  9. #9
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 9
    Points : 6
    Points
    6
    Par défaut
    Bizarrement,j'ai réessayer sur un autre pc en faisant attention a l'adresse (host,user etc)
    ça fonctionne...
    Merci de ta patience Tchize_,je tiendrais au courant sur ce fil de conversation si c'est résolu .


    EDIT: Résolu j'sais d'où sa viens,le port était déjà utiliser,le port 443...
    si vous connaissez,wamp et skype = pas bon ménage (tous les deux utilisent le même port... )

  10. #10
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    le port 443 n'est pas supposé être utilisé par mysql, c'est un port https

  11. #11
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 9
    Points : 6
    Points
    6
    Par défaut
    Oui mais je passe par wamp,pour ma Bdd.
    j'ai fais des test sa viens bien de là,j'avoue être surpris aussi.Mais sans skype sa fonctionne parfaitement.
    je sais que le port par defaut de la Bdd est 3306.
    bref l'erreur incensé pour moi ...
    le principal c'est que sa fonctionne maintenant !

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

Discussions similaires

  1. [MySQL] Requête pour affichage nombre de "likes" / Ajax, PHP, MySQL
    Par E. Nigma dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 10/05/2015, 08h34
  2. JTable dynamique pour affichage d'une requete SQL
    Par boumacmilan dans le forum Composants
    Réponses: 1
    Dernier message: 09/06/2009, 15h01
  3. Réponses: 17
    Dernier message: 17/05/2004, 15h24
  4. code html en ram -> TWebBrowser pour affichage
    Par FredericB dans le forum C++Builder
    Réponses: 2
    Dernier message: 22/04/2003, 22h55
  5. Script pour envoyer des info a mysql
    Par rhum1 dans le forum Linux
    Réponses: 6
    Dernier message: 15/04/2003, 16h19

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