fix<调整数据库链接源>

master
liyansheng 2024-12-21 23:24:33 +08:00
parent 01ecf1a584
commit 91491824ec
3 changed files with 13 additions and 16 deletions

View File

@ -43,7 +43,7 @@ public class UserDao {
public static void main(String[] args) throws Exception {
UserDao userDao = new UserDao();
System.out.println(userDao.getUserById(1).getUsername());
System.out.println(userDao.getAllUser());
}
}

View File

@ -3,22 +3,10 @@ package example.utils;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class DBUtils {
private static ComboPooledDataSource dataSource;
static {
try {
dataSource = new ComboPooledDataSource();
dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/work?useSSL=false&serverTimezone=UTC");
dataSource.setUser("root");
dataSource.setPassword("root");
} catch (Exception e) {
e.printStackTrace();
}
}
// 使用默认配置名 "default-config" 从c3p0-config.xml文件中获取数据源配置
private static ComboPooledDataSource dataSource = new ComboPooledDataSource("default-config");
public static ComboPooledDataSource getDataSource() {
return dataSource;
}
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="driverClass">com.mysql.cj.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/work?serverTimezone=GMT%2B8&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false</property>
<property name="user">root</property>
<property name="password">root</property>
</default-config>
</c3p0-config>