当前位置:网站首页>Create datasource using Druid connection pool
Create datasource using Druid connection pool
2022-07-27 05:12:00 【Autunomy】
Use Druid Connection pool creation DataSource( data source )
There are two ways to create
The first one is
Use Map aggregate , Set each attribute to create
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
public class Test01 {
public static void main(String[] args) throws Exception {
Map<String, String> map = new HashMap();
// Set up URL
map.put(DruidDataSourceFactory.PROP_URL, "jdbc:mysql://10.10.10.134:3306/java20");
// Set the drive Driver
map.put(DruidDataSourceFactory.PROP_DRIVERCLASSNAME, "com.mysql.jdbc.Driver");
// Set the username
map.put(DruidDataSourceFactory.PROP_USERNAME,"root");
// Set the password
map.put(DruidDataSourceFactory.PROP_PASSWORD,"123456");
// create data source
DataSource dataSource = DruidDataSourceFactory.createDataSource(map);
}
}
The second kind
Use properties Configuration file
Create a... In the project root directory resources File and mark it as a resource directory
Create a db.properties And write the following configuration
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://10.10.10.134:3306/java20
username=root
password=123456
To write java class
import com.alibaba.druid.pool.DruidDataSourceFactory;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;
public class Test02 {
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(Test02.class.getClassLoader().getResourceAsStream("db.properties"));
DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
}
}
边栏推荐
猜你喜欢

How do I reset Photoshop preferences? PS method of resetting preferences

Reproduce ssa-gan using the nine day deep learning platform

Dialog introduction

Typescript details

安装Pygame

The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay

strlen和sizeof的区别

Hiding skills of Photoshop clipping tool

How idea creates a groovy project (explain in detail with pictures and texts)

How to sinicize the JMeter interface?
随机推荐
Complete Binary Tree
Use ngrok for intranet penetration
Read write separation and master-slave synchronization
智慧展厅设计的优势及适用行业分析
What is the future development direction of software testing engineers?
How to import PS style? Photoshop style import tutorial
老子云携手福昕鲲鹏,首次实现3D OFD三维版式文档的重大突破
static和final关键字 学习 demo练习
Invert a Binary Tree
二叉搜索树详讲
The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
Sunset red warm tone tinting filter LUTS preset sunset LUTS 1
Test basis 5
二、MySQL高级
There is no need to install CUDA and cudnn manually. You can install tensorflow GPU through a one-line program. Take tensorflow gpu2.0.0, cuda10.0, cudnn7.6.5 as examples
动态内存函数的介绍(malloc free calloc realloc)
一、MySQL基础
Inspiration from "flying man" Jordan! Another "arena" opened by O'Neill
Differences among left join, inner join and right join
MQ message queue is used to design the high concurrency of the order placing process, the generation scenarios and solutions of message squeeze, message loss and message repetition