How to connect Java to MySQL?

MySQLMySQLi Database

To connect Java to MySQL, the Java code is as follows −

import java.sql.Connection;
import java.sql.DriverManager;
public class LostConnectionURLDemo {
   public static void main(String[] args){
      String JDBCURL="jdbc:mysql://localhost:3306/web?autoReconnect=true";
      Connection con=null;
          con = DriverManager.getConnection(JDBCURL,"root","123456");
          System.out.println("connection is established");
      catch(Exception e){

This will produce the following output −

Updated on 24-Dec-2019 07:58:15