将 java 应用程序与在线托管的 mysql 数据库连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26389011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connecting java application with online hosted mysql database
提问by Rafi Abro
I have build an application in java, application is one and will be used on 3 different systems,
And therefore the database of that application must be online to keep all 3 applications with up to date database...
我用 java 构建了一个应用程序,应用程序是一个应用程序,将在 3 个不同的系统上使用,
因此该应用程序的数据库必须在线以保持所有 3 个应用程序都具有最新的数据库...
In starting I developed my application based on localhost (wampserver) and used database in "PhpMyAdmin", and hopefully application is fully developed and ready to run.. but the problem is online database connectivity!
I have uploaded my database on a Sitein PhpMyAdmin and they provided below information:
在开始时,我基于 localhost(wampserver)开发了我的应用程序,并在“PhpMyAdmin”中使用了数据库,希望应用程序已完全开发并准备好运行..但问题是在线数据库连接!我已将我的数据库上传到 PhpMyAdmin 中的站点,他们提供了以下信息:
and the for connecting my app to this DB is:
将我的应用程序连接到此数据库的方法是:
String url = "jdbc:mysql://fdb12.biz.nf:3306/";
String dbName = "1738412_wstore";
String driver = "com.mysql.jdbc.Driver";
String userName = "1738412_wstore";
String password = "Password";
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
now when I run my application it shows below error:
现在,当我运行我的应用程序时,它显示以下错误:
I dont know what the problem is there, please help me out through this..
我不知道那里有什么问题,请帮助我解决这个问题..
回答by sumanta
- Check for firewall.
- Check if mysql is running.
- 检查防火墙。
- 检查mysql是否正在运行。
回答by Suresh Sajja
I faced the same issue and the following helped me to solve.
我遇到了同样的问题,以下帮助我解决了。
http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely
http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely
Hopefully, your hosting provider should have same type of cpanel to configure MySQL database for remote connections.
希望您的主机提供商应该具有相同类型的 cpanel 来配置 MySQL 数据库以进行远程连接。
回答by anupam.singhal
2 things you can try:
您可以尝试 2 件事:
- Install MySql client locally on your machine and connect like:
mysql -h fdb12.biz.nf -u 1738412_wstore -P<password>
- 在您的机器上本地安装 MySql 客户端并像这样连接:
mysql -h fdb12.biz.nf -u 1738412_wstore -P<password>
This should work before you try anything else.
这应该在您尝试其他任何事情之前起作用。
Make sure you're using the right imports in your code. See [here][1].
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException;
确保您在代码中使用了正确的导入。见[这里][1]。
导入 java.sql.Connection; 导入 java.sql.DriverManager; 导入 java.sql.SQLException;
回答by chalitha geekiyanage
I think your DB server doesn't allow remote connections.
我认为您的数据库服务器不允许远程连接。
Try hosting in:
尝试托管:
http://www.freesqldatabase.com/freemysqldatabase/
http://www.freesqldatabase.com/freemysqldatabase/
It's free and allow remote DB connections.
它是免费的并允许远程数据库连接。
Good Luck!!!
祝你好运!!!
回答by Pier-Alexandre Bouchard
Considering the Biz.nfFAQ:
考虑Biz.nf常见问题解答:
How can I connect to my MySQL/PostgreSQL database? What settings should I use for my script/software?
MySQL/PosgreSQL database connection can be established with script/software hosted only on your web hosting account (meaning no remote access is allowed due to security reasons). The following settings are needed:
如何连接到我的 MySQL/PostgreSQL 数据库?我应该为我的脚本/软件使用哪些设置?
MySQL/PosgreSQL 数据库连接可以使用仅托管在您的虚拟主机帐户上的脚本/软件建立(这意味着出于安全原因不允许远程访问)。需要以下设置:
So, since biz.nfdoes not allow remote access, it will be difficult for you to interact with their MYSQL server for your application.
因此,由于biz.nf不允许远程访问,因此您将很难与他们的应用程序的 MYSQL 服务器进行交互。
The best solution and the most simple is probably to find a new provider which will allow the remote access. Heroku.comworks very well.
最好的解决方案和最简单的方法可能是找到一个允许远程访问的新提供商。Heroku.com运行良好。
If you really want to use the biz.nfservices, it will be more difficult.
如果你真的要使用biz.nf服务,那就更难了。
It's not a script or credential problem.
这不是脚本或凭据问题。
Maybe you can (probably not), try to login by SSH to configure your server to enable remote access to your MYSQL database server.
也许您可以(可能不能)尝试通过 SSH 登录以配置您的服务器以启用对 MYSQL 数据库服务器的远程访问。
From the free plan, you will not have any access to the online SSH tool and you will need to configure your domain for a SSH connection.
从免费计划中,您将无法访问在线 SSH 工具,您需要为 SSH 连接配置您的域。
In SSH, and it probably will not work considering the FAQ, you could try to simply modify your /etc/mysql/my.cnf
file by commenting the bind-address
line wich by default only allows local access (127.0.0.1). Then, try to restart your MYSQL service with: a simple service mysql restart
to verify if the remote connection works.
在 SSH 中,考虑到常见问题,它可能不起作用,您可以尝试/etc/mysql/my.cnf
通过注释bind-address
默认情况下仅允许本地访问 (127.0.0.1)的行来简单地修改您的文件。然后,尝试使用以下命令重新启动 MYSQL 服务:service mysql restart
验证远程连接是否有效。
If the remote connection still doesn't work after this, the only way I can find for the moment (unless you completely change your hosting provider) would be to create a kind of API
hosted directly on the server and your Java program could interacts with your services (In JSON, by example).
如果在此之后远程连接仍然不起作用,我目前能找到的唯一方法(除非您完全更改您的托管服务提供商)是API
直接在服务器上创建一种托管,并且您的 Java 程序可以与您的服务(以 JSON 为例)。