
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to make a MySQL Connection in JAVA? What is the port number to set on locahost?
You need to use port number 3306 in the URL. The syntax is as follows −
jdbc:mysql://localhost:3306
Example
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(); } } }
Output
MySQL connection is successful with port 3306.
- Related Articles
- What Is the Default MySQL Port Number?
- MySQL Server port number?
- Fix Connectivity error in Java MySQL connection for connector to be set to class path?
- How to Set Wget Connection Timeout in Linux?
- How to make MySQL result set the same as specified?
- How to keep the connection alive in MySQL Workbench?
- How to work with one database connection object in the entire Java-MySQL application?
- How to find out port of MySQL Server?
- How to display current connection info in MySQL?
- How can I make a browser to browser (peer to peer) connection in HTML?
- What is the MySQL JDBC driver connection string?
- Java – MySQL connection with ipAddress
- How to get the port number of the processes using PowerShell?
- How to set global event_scheduler=ON even if MySQL is restarted?
- Is there a way to make a list from a MySQL table in Java?

Advertisements