【问题标题】:Connect jdbc to a server db将 jdbc 连接到服务器数据库
【发布时间】:2014-09-12 16:18:17
【问题描述】:

本地主机

connection = DriverManager
    .getConnection("jdbc:mysql://localhost:3306/skead","admin", "admin");

这是访问我的本地主机数据库的一种方式。

但是如果我想访问我的服务器数据库(不是本地主机)怎么办? 我该怎么做?

【问题讨论】:

  • 你不能把mysql://localhost:3306/skead改成mysql://>YOUR SERVER IP HERE<:3306/skead吗?
  • 我希望看到来自 downvoter 的 cmets。这将有助于提问者了解他做错了什么
  • "not localhost" - 好吧,用所需的主机名替换 localhost...
  • @Nabin 由于缺乏研究工作,我投了反对票。

标签: java mysql jdbc


【解决方案1】:

那么您需要提供 URL

jdbc:mysql://yourRemoteHost:portToWhichRemoteHostMysqlListens/remoteDBName

【讨论】:

    【解决方案2】:
    connection = DriverManager.getConnection("jdbc:mysql://Server_Name/DBName","UserName", "Password");
    

    【讨论】:

      【解决方案3】:
              String dbURL = "jdbc:mysql://serverIPAddress:3307/db_name";
              String username = "root";
              String password = "redmouse";
      
      //        String dbURLs = "jdbc:mysql://localhost/db_name";
      //        String usernames = "root";
      //        String passwords = "redmouse";
      
            Connection dbCon = DriverManager.getConnection(dbURL, username, password);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-06
        • 1970-01-01
        • 2019-05-24
        • 1970-01-01
        相关资源
        最近更新 更多