简体   繁体   中英

Java - Unable to connect to MySQL Database from Cpanel (godaddy). (Error: java.sql.SQLException: Access denied for user ')

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);
    }
}
}

转到cpanel的“ mysql remote”选项,并允许您ip连接到mysql。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM