Download JDBC
Download Link:MySQL :: Download Connector/J
Select Operating System:Platform Independent
Click No thanks, just start my download.
Extract files and place files in a memorable location.
Create new project in IDEA
1、Create new project.
2、Add a directory.
3、Select lib -> right click -> Opin in -> files -> Import JDBC
Add it as a module
Select testJDBC -> right click -> Project Structure -> Module -> JAR
Create Module in MySQL Workbench
Editor Java Code
In src/Main.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Main {
public static void main(String[] args) {
try {
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/book",
"root", "11");
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select * from advisor");
while (resultSet.next()) {
System.out.println(resultSet.getString("s_ID"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
参考链接
视频参考:Java JDBC - Connect to MySQL Database in IntelliJ with Java - YouTube