URL에 포트 번호 3306을 사용해야 합니다. 구문은 다음과 같습니다 -
jdbc:mysql://localhost:3306
예시
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnectionToJava {
public static void main(String[] args) {
String JDBCURL="jdbc:mysql://localhost:3306/sample?useSSL=false";
Connection con=null;
try {
con = DriverManager.getConnection(JDBCURL,"root","123456");
if(con!=null) {
System.out.println("MySQL connection is successful with port 3306.");
}
}
catch(Exception e) {
e.printStackTrace();
}
}
} 출력
MySQL connection is successful with port 3306.