Probleme avec la connection distant d'un serveur mysql &netbeans

ingtechnologie Messages postés 4 Date d'inscription mercredi 5 juin 2013 Statut Membre Dernière intervention 18 octobre 2013 - Modifié par BunoCS le 16/10/2013 à 16:09
ingtechnologie Messages postés 4 Date d'inscription mercredi 5 juin 2013 Statut Membre Dernière intervention 18 octobre 2013 - 18 oct. 2013 à 10:12
Bonjour,

je développe sur netbeans 7,j'ai créer ma connection avec une BD MySQL en locale j'arrive a me connecter et quand je tente de me connecter avec un serveur distant je n'arrive pas (j'ai un serveur distant (web)q et je voulait utilisé la connection internet pour se connecté) j'ai besoin de votre aide voici mon code:
try{
      // Class.forName("java.sql.Driver");
         Class.forName("com.mysql.jdbc.Driver");
          System.out.println("Driver com.mysql.jdbc.Driver chargé");
       //Connection conn=(Connection)DriverManager.getConnection("jdbc:mysql://topino.fatcowmysql:3306/ciras","ciras","Ciras-2013@1");
       Connection conn=(Connection)DriverManager.getConnection("jdbc:mysql:www.phpmyadmin.toponitech.com:8080/mysql/non_Bd","login","mot de passe"); 
     System.out.println("Driver com.mysql.jdbc.Connexion effectue");
       Statement stmt=conn.createStatement();
       String query="Select * from non_table";
       ResultSet rs=stmt.executeQuery(query);
       
       while (rs.next()){
       String d1=rs.getString("Dir_Code");
       String d2=rs.getString("Dir_Libelle");
       
       model.addRow(new Object[]{d1,d2});
       
       }
       rs.close();
       stmt.close();
       conn.close();
       }catch(Exception e){
       
       JOptionPane.showMessageDialog(this,"Erroor de Connection");
      
       }

mercie encord de votre aide

5 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 344
16 oct. 2013 à 18:52
Bonsoir,
Je pense que la chaine de connexion pour accéder à la BDD ne doit pas être bonne
jdbc:mysql:www.phpmyadmin.toponitech.com:8080/mysql/non_Bd","login","mot de passe"); 



le fait que phpmyadmin soit écrit dedans..me surprend...
Que ce soit l'url que vous utilisiez pour vous connecter à l'interface "manuellement" via PhpMyAdmin.. ok.. mais pas pour accéder à la BDD depuis un programme...
Il faut y mettre plutôt le nom de domaine de votre site (ou serveur).

1
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
16 oct. 2013 à 16:09
Hello,
J'ai édité ton message afin de rajouter les balises codes (4e icone au-dessus de la zone de texte). Merci d'y penser la prochaine fois ;)
0
ingtechnologie Messages postés 4 Date d'inscription mercredi 5 juin 2013 Statut Membre Dernière intervention 18 octobre 2013
Modifié par BunoCS le 17/10/2013 à 09:15
merci pour votre réponse mais sil te plait soi un peut explicite et donne moi un exemple concret pardonne moi si je demande trot.
Connection conn=(Connection)DriverManager.getConnection("jdbc:mysql:www.phpmyadmin.toponitech.com:8080/mysql/ciras","login","password"); quand je tente de changé il me donne un message d'erreur suivant:
ERREUR: No suitable driver found for jdbc:mysql:www.ciras.cg:8080/mysql voice le code:

import java.sql.*; 

public class testConection { 
    public static void main (String[] args) { 
        //Connexion à un serveur Wamp sous Windows 2003 Server 
        String url="jdbc:mysql:www.ciras.cg:8080/mysql"; 
        String login="teste/non_base_donee"; 
        String passwd="mot_passe"; 
        Connection connexion; 

        System.out.println ("Connexion au driver JDBC..."); 
        try{ 
            //DriverManager.setLogWriter(new PrintWriter(System.out)); 
            Class.forName ("com.mysql.jdbc.Driver"); 
            System.out.println ("Driver com.mysql.jdbc.Driver chargé"); 
            connexion = DriverManager.getConnection (url, login, passwd ); 
            System.out.println ("Driver com.mysql.jdbc.Connection effectué"); 

        }catch (Exception ex){ 
            System.out.println ("ERREUR: " + ex.getMessage ()); 
            System.exit (1); 
        } 
    } 
} 

--
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
17 oct. 2013 à 09:16
Re,
Même remarque que précédemment..j'en ai profité également pour modifier les login/password...
Ce serait vraiment sympa de penser à ajouter de toi-même les balises code.
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 344
17 oct. 2013 à 10:29
Bonjour,

Votre chaine de connexion ( String url="jdbc:mysql:www.ciras.cg:8080/mysql";
) n'est surement pas bonne.


Voici la syntaxe :
The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:
jdbc:mysql://[host][,failoverhost...][:port]/[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers.
jdbc:mysql://[host:port],[host:port].../[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

If the database is not specified, the connection will be made with no default database. 



0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
ingtechnologie Messages postés 4 Date d'inscription mercredi 5 juin 2013 Statut Membre Dernière intervention 18 octobre 2013
18 oct. 2013 à 10:12
Hello dear friend and thank you for your help I hope I do not understand your answer, I have a web server or I have a mysql data base and website site works bien.et I am trying to make an application with netbeans GUI for me just has to connect with the database located on the server. Local I connect without problème.et the butts of my project is to make an application to connect to a remote server without the PHP code or other. I hope you will not find his evil I bessouin your help sil te plait. I'll pass my encor parameter that draws you well explained encor:

Français:

Bonjour cher amie et merci pour ton aide j'espère, je n'est pas bien compris ta réponse, j'ai un serveur web ou j'ai une base donnée mysql et un site web le site marche bien.et je suis entrain de faire un application avec netbeans avec interface graphique pour me permettre juste a me connecter avec la base qui se trouve sur le serveur. En locale je me connecte sans problème.et le bute de mon projet c'est de faire un application qui se connecter avec un serveur distant sans passer sur les codes PHP ou autre. J'espère que tu ne trouveras pas sa mal j'ai bessouin de ton aide sil te plait. je te passe encor mes paramètre pour que tu puise bien expliqué encor :

try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver com.mysql.jdbc.Driver chargé");
// Connection conn=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
Connection conn=(Connection)DriverManager.getConnection("jdbc:mysql:www.ciras.cg:8080/BD","login","Password");
System.out.println("Driver com.mysql.jdbc.Connexion effectue");
Statement stmt=conn.createStatement();

String query="Select * from membre";
ResultSet rs=stmt.executeQuery(query);

while (rs.next()){

String d1=rs.getString("id");
String d2=rs.getString("email");
model.addRow(new Object[]{d1,d2});

}
rs.close();
stmt.close();
conn.close();
}catch(Exception e){

JOptionPane.showMessageDialog(this,"Erroor de Connection");
0
Rejoignez-nous