步骤一:导入所需要的jar包(略)如图:
步骤二:编写properties配置文件
具体参考内容如下:
url=jdbc:mysql://localhost:3306/db_wwq
username=root
password=root
driverClassName=com.mysql.cj.jdbc.Driver
initialSize=10
maxActive=20
maxWait=1000
步骤三:编写JdbcUtils工具类java文件
public class JdbcUtils {
private static DataSource dataSource;
private static ThreadLocal<Connection> threadLocal;
static {
try {
//加载连接池配置文件,创建DataSource
Properties properties = new Properties();
properties.load(JdbcUtils.class.getClassLoader().getResourceAsStrea