This commit is contained in:
wu 2024-11-06 09:15:16 +08:00
parent f359fd3a56
commit 9a9c1c6b21
2 changed files with 5 additions and 3 deletions

View File

@ -25,6 +25,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2:2.1.214'
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
}

View File

@ -8,7 +8,8 @@ import java.sql.SQLException;
public class JdbcCrudExample {
private static final String DB_URL = "jdbc:mysql://localhost:3306/paopao";
// private static final String DB_URL = "jdbc:mysql://localhost:3306/demo";
private static final String DB_URL = "jdbc:h2:file:./demo.db";
private static final String USER = "root";
private static final String PASS = "root";
@ -16,8 +17,8 @@ public class JdbcCrudExample {
Connection conn = null;
try {
// 加载MySQL驱动
Class.forName("com.mysql.cj.jdbc.Driver");
// Class.forName("com.mysql.cj.jdbc.Driver");
Class.forName("org.h2.Driver");
// 获取数据库连接
conn = DriverManager.getConnection(DB_URL, USER, PASS);