1. Download MySQL database and install and configure it Download address: https://dev.mysql.com/downloads/installer/ 2. Download the JDBC Connector Download address: mysql-connector-java-8.0.22 After downloading the compressed package and decompressing it, find the mysql-connector-java-8.0.22.jar file and put it in the path you specified. 3. Import jar package into the project Test class Test.java code for testing database connection: import java.sql.Connection; import java.sql.DriverManager; public class Test { public static void main(String[] args) { String driverName = "com.mysql.cj.jdbc.Driver"; String dbURL="jdbc:mysql://localhost:3306/websql?&useSSL=false&serverTimezone=Asia/Shanghai"; //websql is the database name String userName = "root"; String userPwd = "root"; try { Class.forName(driverName); Connection con = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println("Connecting to database successfully"); } catch (Exception e) { e.printStackTrace(); System.out.print("Connection failed"); } } } This is the end of this article about how to use Java to connect to MySQL database in IntelliJ IDEA. For more information about how to use Java to connect to MySQL database in IntelliJ IDEA, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: In-depth understanding of the creation and implementation of servlets in tomcat
>>: vue+element-ui implements the head navigation bar component
I recently upgraded a test server operating syste...
The smallest scheduling unit in k8s --- pod In th...
Preface In Linux kernel programming, you will oft...
When we are writing a page, we often encounter a ...
Today I installed the MySQL database on my comput...
1. First stop the mysql service As an administrat...
Table of contents Preface What are constructible ...
When using CSS pseudo-elements to control element...
Some of you may have heard that the order of trav...
Table of contents 1. Content Overview 2. Concepts...
A Docker container starts a single process when i...
Static files Nginx is known for its high performa...
On Linux, bash is adopted as the standard, which ...
First of all, let me talk to you about my daily l...
Table of contents 1. Introduction 2. Detailed exp...