我只是尝试使用java应用程序.But远程连接到我的MySQL服务器,同时运行代码从服务器获取java.sql.SQLException:null,消息:“主机'202.146.192.145‘不允许连接到这个MySQL服务器”.I已经仔细检查了主机,用户名和password.Following是我的应用程序中给出的数据库连接代码。
package com.db;
public class Dbbean {
    public Connection con;
    public Statement st;
    public PreparedStatement pst;
    public Dbbean(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://phpmyadmin202.sample.com/dbname","user","password");
            st=con.createStatement();
        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public void close() throws SQLException{
        con.close();
    }
    public ResultSet execsql(String sql) throws SQLException{
        ResultSet r=st.executeQuery(sql);
        return(r==null)?null:r;
    }
    public int updatesql(String sql) throws SQLException, ClassNotFoundException{
        int r=st.executeUpdate(sql);
        return(r==0)?0:r;
    }
}发布于 2018-03-08 14:58:15
检查您的服务器中的用户和权限。
https://stackoverflow.com/questions/49151154
复制相似问题