如何使用主机名和端口8080远程访问myphpadmin

时间:2017-10-13 05:00:34

标签: java mysql sql jdbc

所以我知道这已被问了很多,我已经在这里找到答案,但我有一个ddns通过没有IP,我试图通过Java访问我的数据库我的代码如下

package POJOS;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DBConnection 
{
   private Connection connection;
   private Statement statement;
   private ResultSet resultSet;

    public DBConnection() 
    {
        connectToDB();
    }
    private void connectToDB()
    {
        String 
                driver = "com.mysql.jdbc.Driver",
                url = "jdbc:mysql://clubdatabase.ddns.net:8080/programming_club",
                userName = "root",
                password = "";
       try 
       {
           Class.forName(driver); 
           connection = (Connection) DriverManager.getConnection(url,userName,password);
           System.out.println("Connection to server successful!");
       }
       catch (ClassNotFoundException ex) 
       {
           Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
       } catch (SQLException ex) {
           Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
       }
    }
    public static void main(String[] args) {
        DBConnection dBConnection = new DBConnection();
    }
}

所以如果你输入网址中的地址它会带你到我的服务器我甚至试图把/ phpmyadmin / programming_club但它仍然无法正常工作。有没有人知道为什么?

1 个答案:

答案 0 :(得分:-2)

创建连接

connection = DriverManager.getConnection(url,username,password)