0

I want to connect mysql database located at hosting server (e.g. godaddy) using ssh technique (because it does not allow direct connection) in android javafx (using javafxmobile-plugin) project.

I scussfully connected to mysql database using ssh with running in my desktop pc (window). But when i run it on the android it all stuck....

Currently my codding is...

.java file:

public static final Integer PORT = 53009;

public static final String DB_NAME = "";
public static final String DB_URL = "jdbc:mysql://localhost:" + PORT + "/" + DB_NAME;
public static final String USERNAME = "";
public static final String PASSWORD = "";

public static final String DRIVER = "com.mysql.cj.jdbc.Driver";

--------------------------------------------------------

Connection con = null;
Session session = null;

//Fields
String rHost = "";
String user = "";
String password = "";

int rPort = 3306;

public void getRootConnection() throws SQLException {
    close();

    try {
        //Create the JSCH object
        JSch jsch = new JSch();

        //Get the session
        session = jsch.getSession(user, rHost);

        //Set the password
        session.setPassword(password);

        //To be able to connect to any host (this is just for testing!)
        session.setConfig("StrictHostKeyChecking", "no");

        //Connect the session
        session.connect();

        //Set port forward
        session.setPortForwardingL(PORT, "localhost", rPort);

        //Show message
        System.out.println("Waiting for connections…");

        //mysql database connectivity
        Class.forName(DRIVER).newInstance();

        con = DriverManager.getConnection(DB_URL, USERNAME, PASSWORD);

        System.out.println("Database connection established");
        System.out.println("DONE");
    } catch (ClassNotFoundException | JSchException | InstantiationException | IllegalAccessException ex) {
        Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void close() {
    try {
        if (con != null && !con.isClosed()) {
            System.out.println("Closing Database Connection");
            con.close();
        }
        if (session != null && session.isConnected()) {
            System.out.println("Closing SSH Connection");
            session.disconnect();
        }
    } catch (SQLException ex) {
        Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
    }
}

.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.3.16'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.maqboolsolutions.Main'

dependencies {
    compile 'com.gluonhq:charm:5.0.2'
    
    compile 'mysql:mysql-connector-java:8.0.13'
    compile 'com.jcraft:jsch:0.1.54'
}

jfxmobile {
    downConfig {
        version = '3.8.6'
        // Do not edit the line below. Use Gluon Mobile Settings in your project context menu instead
        plugins 
    }
    android {
        manifest = 'src/android/AndroidManifest.xml'
        
        javafxportsVersion = '8.60.11'
 
        android {
            manifest = 'src/android/AndroidManifest.xml'
        
            packagingOptions {
                exclude 'META-INF/INDEX.LIST'
            }
        
            dexOptions {
                javaMaxHeapSize "4g"
            }
        }
    }
}

If you like to help me and want to test your own this is the link to the project located at github mysql-ssh-android test project

My main problem is that when i run it on android, ssh connection works. also forwarded ports works. but when i connect mysql using localhost and forwarded port, my app suddenly close with error unresponsive..

Any help?

If you need more info. I am ready. Please help me if you can???

Community
  • 1
  • 1
  • see my post https://serverfault.com/questions/943115/connecting-to-mysql-over-ssh-in-javafx-android – CTO - Abid Maqbool Dec 07 '18 at 07:11
  • Ok! Ok! Ok!.......... i add a full simple testing project at github account it is fully working in desktop and android. Build in in android and see stacktrace. and help me. It is urgent project. please if anyone can help..... link to project: https://github.com/AbidMaqbool/mysql-ssh-android – CTO - Abid Maqbool Dec 07 '18 at 09:06
  • I know that's if it is urgent project then only for mine. not for you. Ok. Thanks. The problem is that in desktop (window) it works as i expected but when in run it in adroid mobile. SSH connection is Ok. But when i used to connect to mysql (after forwarding port) using localhost and and forwarded port my app shut down (closed unexpectedly)... – CTO - Abid Maqbool Dec 07 '18 at 10:10
  • Way better. Though without a log, I do not think anyone will be able to help you. – Martin Prikryl Dec 07 '18 at 10:58
  • Ok! Please help me. If Android Device Monitor is used for log. or any other? Also If `Android Device Monitor` should be used then what should be used filter criteria e.g. error, verbose, debug, info or warn. i am new in debuging.... – CTO - Abid Maqbool Dec 07 '18 at 11:06
  • I do not not anything about logging on Android. – Martin Prikryl Dec 07 '18 at 11:27
  • Finaly after a lot of searching on the internet, I generated complete log_cate using `Android Device Monitor`. Please see the errors and help me if any? [Log_verbox.txt][1] [log_info.txt][2] [log_error.txt][3] [log_debug][4] [1]: https://github.com/AbidMaqbool/mysql-ssh-android/blob/master/log_verbos.txt [2]: https://github.com/AbidMaqbool/mysql-ssh-android/blob/master/log_info.txt [3]: https://github.com/AbidMaqbool/mysql-ssh-android/blob/master/log_error.txt [4]: https://github.com/AbidMaqbool/mysql-ssh-android/blob/master/log_debug.txt – CTO - Abid Maqbool Dec 07 '18 at 12:38
  • Would you add one more logging entry before `getConnection`? + Also use consistently `localhost` or `127.0.0.1`. Do not mix them. + And enable [Paramiko logging](https://stackoverflow.com/q/27587716/850848). – Martin Prikryl Dec 07 '18 at 12:44
  • please see this link i use localhost in both locations... and generated log_cat of that's project. `Paramiko logging` what's mean... – CTO - Abid Maqbool Dec 07 '18 at 12:56
  • Please use my github lnik and see stack trace also test project at your own. And solve my problem... – CTO - Abid Maqbool Dec 07 '18 at 14:48
  • I see `localhost` in `DB_URL`, but `127.0.0.1` in `setPortForwardingL` call. + What is not clear about my request for Paramiko log file? – Martin Prikryl Dec 07 '18 at 14:57
  • Ok! i changed `localhost` from `127.0.0.1` in my origanl question & test but again the same error. I previous mentioned that i already used localhost as in this link https://github.com/AbidMaqbool/mysql-ssh-android/blob/master/mysql_ssh_android/mysql_ssh_androidApp/src/main/java/com/maqboolsolutions/mysql_ssh_android/DBConnection.java . sorry for confusing... also test and logs that project. – CTO - Abid Maqbool Dec 08 '18 at 04:24
  • Where is Paramiko log? – Martin Prikryl Dec 08 '18 at 09:08
  • how can i get `Paramiko log` for javafx android project. I don't find any thing `Paramiko log` in java on the internet..... – CTO - Abid Maqbool Dec 08 '18 at 09:37
  • I've sent you a link yesterday already! https://stackoverflow.com/q/27587716/850848 – Martin Prikryl Dec 08 '18 at 09:47
  • But i have very little experience in python. Please help me in exact direction (witch command should i execute in python shell). Also my application works correctly in desktop pc (javafxports application). – CTO - Abid Maqbool Dec 09 '18 at 05:04

0 Answers0