Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have a Java application that requires a connection to an external MySQL database. However, we have a restricted list of ip addresses that are able to log into the computer.The issue is one of our clients travels and therefore has a dynamic ip address. We have chosen the route to use http://www.noip.com to take into consideration the dynamic ip address. However, there's the issue on how to link the two programs together. The java application still refers to [ip address].hlrn.qwest.net rather than [sub-domain].no-ip.biz.

Is there a function I can use in Java to override what my ip address is used to connect to the database?

Thanks.

share|improve this question
    
It seems this is stand alone application. Otherwise dynamic IP is irrelevant. – AlexR May 21 '13 at 4:18
    
It's a standalone application. – user2360813 May 21 '13 at 4:20

2 Answers 2

Ideally, the connection string should have been externalised so that it could be modified easily. If it's more of a policy constraint on IPs then I think whichever way we do it; it could still be considered a violation. Anyway, I'm assuming you have already given it a thought.

On any OS you have a HOSTS file that can be used to override DNS name resolution. The only constraint is that you can only map IPs not a hostname to another hostname. You could however alias a hostname that's already mapped to an IP. For example, if you add the below

127.0.0.1    [ip address].hlrn.qwest.net

to your HOSTS file (which by the way is located at C:\WINDOWS\system32\drivers\etc\hosts on Windows) your Java application would start making connections to the localhost only. So, you could add the following to redirect and make your Java application connect to no-ip.biz instead.

ip.add.re.ss    [sub-domain].no-ip.biz    [ip address].hlrn.qwest.net

To make this DNS process automatic and redirect without dealing with the actual IP is not easy and requires fiddling with your own DNS setup.

share|improve this answer
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class Conne {
    public static Connection GetConnection() throws ClassNotFoundException,SQLException
    {

        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://ip address /database name","username","password");
        return connection;
    }
}

after creating this class you can use the reference or object of this class for connection purpose....i think that will be helpful to you..... :) :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.