mirror of
https://gitee.com/many2many/java-web.git
synced 2025-01-11 14:40:55 +08:00
jdbc
This commit is contained in:
parent
f359fd3a56
commit
9a9c1c6b21
@ -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'
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user