Java – MySQL connection with ipAddress


Set the JDBC MySQL URL in the DriverManager.getConnection to connect with IP Address. Following is the code to connect using IP Address −

Example

import java.sql.Connection;
import java.sql.DriverManager;
public class JavaIP {
   public static void main(String[] args) {
      String hostURL = "jdbc:mysql://192.168.43.144:3306/web?useSSL=false";
      Connection con = null;
      try {
         con = DriverManager.getConnection(hostURL, "root", "123456");
         System.out.println("connection successful via ip address");
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Output

This will produce the following output −

connection successful via ip address

Here is the snapshot of the output −

Updated on: 17-Dec-2019

583 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements