skip to Main Content

I am unable to connect to the database on my website. The user account has permissions and the user name and password are correct. The only thing that could be wrong is the link I am using for the database because I am just doing “http://” as my link. I am assuming the database is there. Godaddy cPanel portal will not show me where it directly is at.

I do not want to do localhost, I want to connect from Java to an actual database on my cPanel.

NOT actual credentials.

In output it says:

run: Error: java.sql.SQLException: Access denied for user 'usertest'@'test.com' (using password: YES) java.lang.NullPointerException BUILD SUCCESSFUL (total time: 0 seconds)

Code:

Main:

package main;

public class main {

public static void main(String[] args) {
    db connect = new db();
    connect.getData();
}

}

db:

package main;
import java.sql.*;

public class db {

private Connection con;
private Statement st;
private ResultSet rs;

public db(){
    try{
        Class.forName("com.mysql.jdbc.Driver");

        con = DriverManager.getConnection("jdbc:mysql://","usertest","test1");
        st = con.createStatement();

    }catch(Exception ex){
            System.out.println("Error: "+ex);
    }
}

public void getData() {
    try{

        String query = "select * from persons";
        rs = st.executeQuery(query);
        System.out.println("Records from Database");
        while(rs.next());
        String name= rs.getString("name");
        String age = rs.getString("age");
        System.out.println("Name: "+name+" "+"Age"+age);

    }catch(Exception ex){
        System.out.println(ex);
    }
}
}

2

Answers


  1. Chosen as BEST ANSWER

    Found out how to connect, I just did a % only wildcard and it worked. I tried using my IP adresses and IP adresses with wildcards but only a % seemed to work for now.


  2. Go the the cpanel “mysql remote” option and allow you ip to connect to mysql.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search