Phpmyadmin and Java

0

I'm trying to make a BDD server, to be able to connect with java (ide: netbeas), the question is how is the class connection, since I think that is my problem here to access the database that I believe in phpmyadmin Obvious story with ip publica ... Should I open ports? So I have my class connection:

public void init(){
   try{
    Class.forName("com.mysql.jdbc.Driver");
    con=DriverManager.getConnection("jdbc:mysql://miippublica:puertoconelqueaccedoaphpmyadmin/prueba","user", "password");

    }
    
asked by Hector 16.06.2018 в 06:17
source

1 answer

0

If the server hosts you and wants to "open it to the internet" if you are going to have to open ports, regarding what you have put in your code, I am not entirely sure if it is correct. To check it, instead of using your public ip (assuming that this server that you host is local, if not, use the public ip), use localhost:

Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql://localhost:puerto/prueba","user", "password");

If it does not work like this, the problem is in its public ip, or it is not configured correctly, or the port is not open (although I repeat that if the server is in localhost it is not necessary to open it to be able to test it locally). / p>

On the documentation of the jdbc library, the syntax they use to connect is different from the one you have, so you could also try the following code:

Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/prueba?" +
                               "user=user&password=pass");

Substituting the values of user and pass for yours.

    
answered by 16.06.2018 в 11:53