我想连接 mysql database
位于托管服务器(如godaddy)上,使用 ssh
android javafx(使用javafxmobile插件)项目中的技术(因为它不允许直接连接)。
我使用ssh在我的桌面pc(窗口)上运行,成功地连接到mysql数据库。但当我在安卓上运行它时,一切都卡住了。。。。
目前我的密码是。。。
.java文件:
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);
}
}
格雷德尔先生:
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"
}
}
}
}
如果你想帮助我,并想测试自己的这是链接到项目位于github mysql ssh android测试项目
我的主要问题是,当我在android上运行它时,ssh连接工作正常。也可以工作。但是当我使用localhost和forwarded端口连接mysql时,我的应用程序突然错误地关闭了 unresponsive
..
有什么帮助吗?
如果你需要更多信息。我准备好了。如果可以的话,请帮帮我???
暂无答案!
目前还没有任何答案,快来回答吧!