Gabriel Larbi
Gabriel Larbi

Reputation: 3

My java connection returns a connection to server failure

Below is my connection to the server

Class.forName("com.mysql.jdbc.Driver");
       Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:81/user", "root", "");
       JOptionPane.showMessageDialog(null, "Connection Established");
       return conn;
       }catch (Exception e){
           JOptionPane.showMessageDialog(null, e);
          return null;
       }

The actual connection can be found on this line:

DriverManager.getConnection("jdbc:mysql://localhost:81/user", "root", "");

am using port 81 for mysql database because port 80 is being used by another program.

Please I need help solving this problem. And thanks in advance.

Upvotes: 0

Views: 79

Answers (2)

Binu George
Binu George

Reputation: 1070

am using port 81 for mysql database because port 80 is being used by another program.

The default TCP/IP port on which the MySQL server is listening is 3306 not 80. MySQL defaults to port 3306 unless you specify another one in the "my.cnf" config file . Then it is very likely you are using the default 3306 port. Try using the default port unless you changed it.

Upvotes: 1

nitin.sharma0180
nitin.sharma0180

Reputation: 481

Try Below steps to find possible reason

1.Manually Ping and connect to Mysql Database from command line and check if you are able to connect or not.

2.Handle Java Exception in your code and print Exception Object.

3.Check if your server /Database is up and running.

4.Also if you have a MYSQl Client first try to connect from front end ,if you are able to connect then we you need to look into the JDBC Api Code and print the Exception and put System.out after each line of code.

Upvotes: 0

Related Questions