Results 1 to 3 of 3
  1. #1
    Twistx77 is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default Problem Connecting to remote MySQL DB

    Hi everyone!

    I've been trying to connect to a MySQL server that I have at 1&1 Hosting. The problems is that I can't connect to it using Java. It works with my WordPress but I cannot access it using Java.

    Java Code:
     import java.sql.*;
    
    public class Main {
    
        static String bd = "dbname";
        static String login = "username";
        static String password = "pass";
        static String url = "jdbc:mysql://db340.1and1.es/"+ bd;
    
    
        public static void main(String[] args) throws Exception {
         
            Connection conn = null;
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                System.out.println(url);
                conn = DriverManager.getConnection(url, login, password);
                if (conn != null) {
                    System.out.println("Connected to " + url + " ... Ok");
                    conn.close();
                }
            } catch (SQLException ex) {
                System.out.println("Can't connect to the db " + url);
                System.out.println(ex);
            } catch (ClassNotFoundException ex) {
                System.out.println(ex);
            }
        }
    }
    This is the output I get when running that program

    Can't connect to the db jdbc:mysql://db340.1and1.es/db348375357
    com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

    ** BEGIN NESTED EXCEPTION **

    java.net.UnknownHostException
    MESSAGE: db340.1and1.es

    STACKTRACE:

    java.net.UnknownHostException: db340.1and1.es
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddre ss.java:850)
    at java.net.InetAddress.getAddressFromNameService(Ine tAddress.java:1201)
    at java.net.InetAddress.getAllByName0(InetAddress.jav a:1154)
    at java.net.InetAddress.getAllByName(InetAddress.java :1084)
    at java.net.InetAddress.getAllByName(InetAddress.java :1020)
    at com.mysql.jdbc.StandardSocketFactory.connect(Stand ardSocketFactory.java:246)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
    at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2771)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1 555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
    at java.sql.DriverManager.getConnection(DriverManager .java:582)
    at java.sql.DriverManager.getConnection(DriverManager .java:185)
    at sql.Main.main(Main.java:32)


    ** END NESTED EXCEPTION **

    I've checked username, password, dbname and server. In fact I went into my PHP myAdmin and double checked and everything is supossed to be alright.

    any help would be much appreciated!

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    java.net.UnknownHostException: db340.1and1.es
    the unknown host exception means from where you are trying to connect from, this DNS name is not resolvable. (e.g. try to ping this from the command prompt).

  3. #3
    Twistx77 is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    You are right when I try to ping that address I don't get response. I tried to connect using only 1and1.es and no it says it can connect. I also tried using my domain name and it doesn't work either. How can I know what is the right address??

Similar Threads

  1. Problem connecting to mysql database
    By Kelly in forum JDBC
    Replies: 18
    Last Post: 07-22-2010, 06:40 AM
  2. Connecting a MySQL DB through Eclipse
    By mitty in forum New To Java
    Replies: 3
    Last Post: 02-01-2010, 09:22 AM
  3. connecting to remote SQL server
    By mahasarathi in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 04-04-2009, 06:11 AM
  4. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 11:33 AM
  5. connecting to mysql database
    By javagal in forum NetBeans
    Replies: 2
    Last Post: 08-04-2007, 12:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •