【问题标题】:how to connect to multiple data base in online?如何在线连接多个数据库?
【发布时间】:2014-06-03 17:53:45
【问题描述】:

我正在尝试连接到多个数据库,这是我的代码,此代码在本地机器上运行良好,但是当我将其上传到网上时,它无法正常工作,我可以得到任何帮助提前谢谢你。

package dbase.sqlcon;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionHelper{
    private String url;
    private String restrnturl;
    private String prptyurl;
    private String user= "root";
    private String pass= "mysql";
    private String userRestaurent= "root";
    private String passRestaurent= "mysql";
    private String userProperty= "root";
    private String passProperty= "mysql";

    private ConnectionHelper() {
        try {
            Class.forName("com.mysql.jdbc.Driver");

            URLDecoder.decode(getClass().getClassLoader().getResource("flex/testdrive").toString(), "UTF-8");



            url = "jdbc:mysql://192.168.10.1:3306/desisquare";
            restrnturl="jdbc:mysql://192.168.10.1:3306/foodndine";
            prptyurl="jdbc:mysql://192.168.10.1:3306/postaproperty";

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        if (instance == null) {
            instance = new ConnectionHelper();
        }
        return DriverManager.getConnection(instance.url, instance.user, instance.pass);
    }
    public static Connection getConnectionrestaurent() throws SQLException {
        if (instance == null) {
            instance = new ConnectionHelper();
        }
        return DriverManager.getConnection(instance.restrnturl, instance.userRestaurent, instance.passRestaurent);
    }
    public static Connection getConnectionproperty() throws SQLException {
        if (instance == null) {
            instance = new ConnectionHelper();
        }
        return DriverManager.getConnection(instance.prptyurl, instance.userProperty, instance.passProperty);
    }

}

当我问我的托管服务提供商有什么问题时,他发给我这个对我来说非常新的问题

INFO | jvm 1 | 2014/04/18 06:23:03 | Exception is ;java.sql.SQLException: Access denied for user 'postaproperty'@'localhost' (using password: YES)
INFO | jvm 1 | 2014/04/18 06:23:03 | Exception is ;java.sql.SQLException: Access denied for user 'postaproperty'@'localhost' (using password: YES)
INFO | jvm 1 | 2014/04/18 06:23:03 | Exception is ;java.sql.SQLException: Access denied for user 'foodndine'@'localhost' (using password: YES)

【问题讨论】:

  • 你检查你的登录数据了吗?
  • yaaa 我已经检查过了。
  • 在 SO 中找到一个链接。检查stackoverflow.com/questions/1457716/…。还有一件事只是为了调试。仅使用 postaproperty 并部署代码。
  • 您是否可以使用您在此处提供的代码登录您的在线数据库?

标签: java mysql database database-connection


【解决方案1】:

也有可能出错的事情。但是正如您所提到的,一旦您尝试从外部访问您的数据库,就会出现问题,而此类异常消息可能表明您的数据库由于以下原因而无法访问:

-在 my.cnf 中,您应该确认 --skip-networking 已被注释掉:

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# skip-networking

也就是说你的数据库通过 TCP/IP 接受消息

  • 验证您的数据库服务器正在侦听 3306 端口
  • 验证 192.168.10.1 是否可以从您的部署站点 (telnet 192.168.10.1:3306) 访问,因为可能有防火墙阻止了该端口或 DNS 不知道此 IP 地址。

【讨论】:

  • xampp 中的 my.cnf 在哪里?
猜你喜欢
  • 1970-01-01
  • 2010-12-27
  • 2020-07-04
  • 1970-01-01
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多