fix<调整数据库链接源>
parent
01ecf1a584
commit
91491824ec
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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&useUnicode=true&characterEncoding=utf-8&useSSL=false</property>
|
||||
<property name="user">root</property>
|
||||
<property name="password">root</property>
|
||||
</default-config>
|
||||
</c3p0-config>
|
Reference in New Issue