0
package GoldenGate;
import  java.sql.Connection;        
import  java.sql.Statement;     
import  java.sql.ResultSet;     
import  java.sql.DriverManager;     
import  java.sql.SQLException;  

public class  SQLConnector 
{               
    public static void  main(String[] args) throws  ClassNotFoundException, SQLException 
    {                                                   

        //Load mysql jdbc driver        
        Class.forName("com.mysql.jdbc.Driver");     

        //Create Connection to DB       
        Connection con = DriverManager.getConnection("jdbc:mysql://10.1.0.22:3310/test_db","rax","rax@123");

        //Create Statement Object       
       Statement stmt = con.createStatement();  

        // Execute the SQL Query. Store results in ResultSet        
        ResultSet rs= stmt.executeQuery("select *  from users;");                           

        // While Loop to iterate through all data and print results     
        while (rs.next())
        {
            String myName = rs.getString(1);                                        
            String myAge = rs.getString(2);                                                
            System. out.println(myName+"  "+myAge);                     
        }       
         // closing DB Connection       
        con.close();            
    }
}

how to connect to database which have private IP. Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Komal12
  • 3,340
  • 4
  • 16
  • 25

0 Answers0