0

I have a remotely hosted database. I had been working on an FX application for which I connected to localhost for reading and writing data from database. But now I want to connect my desktop application to the remotely hosted database and read and write data from there. But it shows me the following error.



    SEVERE: null
    java.sql.SQLException: null,  message from server: "Host '103.253.39.4' is not allowed to connect to this MySQL server"
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1037)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2239)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2270)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2069)
        at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:44)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:389)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:270)
        at com.garciaPlumbing.model.DatabaseManager.connect(DatabaseManager.java:38)
        at com.garciaPlumbing.model.FittingDetails.getAllSuppliers(FittingDetails.java:155)
        at com.garciaPlumbing.view.Layout_AddFittingType.(Layout_AddFittingType.java:52)
        at com.garciaPlumbing.view.Layout_InsertFittingDetails.(Layout_InsertFittingDetails.java:37)
        at com.garciaPlumbing.view.MenuItemTask.(MenuItemTask.java:23)
        at com.garciaPlumbing.view.BasicLayout.(BasicLayout.java:40)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:340)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$148(LauncherImpl.java:327)
        at com.sun.javafx.application.LauncherImpl$$Lambda$43/445051633.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
        at com.sun.javafx.application.PlatformImpl$$Lambda$44/1775282465.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
        at com.sun.javafx.application.PlatformImpl$$Lambda$47/2028529302.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
        at com.sun.javafx.application.PlatformImpl$$Lambda$45/2040495657.run(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
        at com.sun.glass.ui.win.WinApplication$$Lambda$37/1558600329.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)

    Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
    Caused by: java.lang.NullPointerException
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:358)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
        ... 5 more
    java.lang.ExceptionInInitializerError
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:340)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$148(LauncherImpl.java:327)
        at com.sun.javafx.application.LauncherImpl$$Lambda$43/445051633.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
        at com.sun.javafx.application.PlatformImpl$$Lambda$44/1775282465.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
        at com.sun.javafx.application.PlatformImpl$$Lambda$47/2028529302.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
        at com.sun.javafx.application.PlatformImpl$$Lambda$45/2040495657.run(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
        at com.sun.glass.ui.win.WinApplication$$Lambda$37/1558600329.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.NullPointerException
        at com.garciaPlumbing.model.FittingDetails.getAllSuppliers(FittingDetails.java:171)
        at com.garciaPlumbing.view.Layout_AddFittingType.(Layout_AddFittingType.java:52)
        at com.garciaPlumbing.view.Layout_InsertFittingDetails.(Layout_InsertFittingDetails.java:37)
        at com.garciaPlumbing.view.MenuItemTask.(MenuItemTask.java:23)
        at com.garciaPlumbing.view.BasicLayout.(BasicLayout.java:40)
        ... 16 more

This what I have done to establish the connection.



    public class DatabaseManager {
        private static final String CLASS_FORNAME = "com.mysql.jdbc.Driver";
        private static final String DATABASE_LOCATION = "jdbc:mysql://mysql.2freehosting.com/";//"jdbc:mysql://localhost:3306/";
        private static final String DATABASE_NAME = "u821323799_grc?";//"GarciaPlumbing2";
        private static final String USERNAME = "u821323799_grc";//"root";

        protected static Connection connection = null;
        protected static PreparedStatement statement = null;

        /**
         * 
         * Connect() method is responsible for establishing any connection to database.
         * 
         */
        public static void connect(){
            try {
                Class.forName(CLASS_FORNAME);
                connection = (Connection) DriverManager.getConnection(
                        "jdbc:mysql://mysql.2freehosting.com/u821323799_grc?"
                        + "user=u821323799_grc&password=celloviii1");
            } catch (ClassNotFoundException | SQLException ex) {
                Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
            }        
        }
    }

Please someone help me out with a better solution.

Thanks in advance.

  • It seems that the problem is not at the code, and in the host server, which you need to allow remote connections, specifically the host you're trying from – Avihoo Mamka Jul 03 '16 at 14:22
  • 1
    Is it wise to post the username and password in plain text on the Internet? I hope those aren't the real credentials. Read up on how to GRANT permissions to a given username, password, and host. – duffymo Jul 03 '16 at 14:34

1 Answers1

0

java.sql.SQLException: null, message from server: "Host '103.253.39.4' is not allowed to connect to this MySQL server"

It means that the MySQL Server at the remote system is not configured to accept remote connection from 103.253.39.4 with the provided credentials. Please configure the remote MySQL Server to accept remote connection and try again.

You may try: How to allow remote connection to mysql

Community
  • 1
  • 1
Sanjeev Saha
  • 2,632
  • 1
  • 12
  • 19