Home > Back-end >  With Druid using JDBC connection pool
With Druid using JDBC connection pool

Time:09-28


//1. Import the jar package
//2. Import the configuration file
//3. Load the configuration file
Properties pro=new Properties();
InputStream resourceAsStream=DruidDemo. Class. GetClassLoader () getResourceAsStream (" druid. Properties ");
Pro. The load (resourceAsStream);

//4. Access to the database connection pool objects
The DataSource ds=DruidDataSourceFactory. CreateDataSource (pro);
//5. To get connection object
The Connection Connection=ds. GetConnection ();
System. The out. Println (connection);


this is the code I run, but appeared the following questions, configuration files under the SRC
Jar package is as follows: mysql connector - Java - 8.0.19. Jar
Druid - 1.0.9. Jar

Time zone problem has add
This is my druid. The properties file
DriverClassName=com) mysql). The JDBC Driver
Url=JDBC: mysql:///first? ServerTimezone=UTC
The username=root
Password=123
InitialSize=5
MaxActive=10
MaxWait=3000



. Warning: always resolve com. Mysql. JDBC Connection. Ping method. Will use 'SELECT 1' home.
Java. Lang. NullPointerException
At com. Alibaba. Druid. Pool. Vendor. MySqlValidConnectionChecker. & lt; init> (MySqlValidConnectionChecker. Java: 48)
At com. Alibaba. Druid. Pool. DruidDataSource. InitValidConnectionChecker (DruidDataSource. Java: 878)
At com. Alibaba. Druid. Pool. DruidDataSource. Init (DruidDataSource. Java: 594)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 915)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 911)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 98)
The at cn. Itcast. Datasoure. Druid. DruidDemo. Main (DruidDemo. Java: 24)

On April 26, 2020 com 10:14:44 morning. Alibaba. The druid. Pool. DruidDataSource error
Severe: init datasource error
Java. SQL. SQLException: validateConnection false
At com. Alibaba. Druid. Pool. DruidAbstractDataSource. ValidateConnection (DruidAbstractDataSource. Java: 1216)
At com. Alibaba. Druid. Pool. DruidAbstractDataSource. CreatePhysicalConnection (DruidAbstractDataSource. Java: 1439)
At com. Alibaba. Druid. Pool. DruidDataSource. Init (DruidDataSource. Java: 618)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 915)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 911)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 98)
The at cn. Itcast. Datasoure. Druid. DruidDemo. Main (DruidDemo. Java: 24)

On April 26, 2020 com 10:14:44 morning. Alibaba. The druid. Pool. DruidDataSource error
Severe: a dataSource init error
Java. SQL. SQLException: validateConnection false
At com. Alibaba. Druid. Pool. DruidAbstractDataSource. ValidateConnection (DruidAbstractDataSource. Java: 1216)
At com. Alibaba. Druid. Pool. DruidAbstractDataSource. CreatePhysicalConnection (DruidAbstractDataSource. Java: 1439)
At com. Alibaba. Druid. Pool. DruidDataSource. Init (DruidDataSource. Java: 618)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 915)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 911)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 98)
The at cn. Itcast. Datasoure. Druid. DruidDemo. Main (DruidDemo. Java: 24)

On April 26, 2020 com 10:14:44 morning. Alibaba. The druid. Pool. DruidDataSource info
Information: {} dataSource - 1 inited
The Exception in the thread "main" Java. SQL. SQLException: validateConnection false
At com. Alibaba. Druid. Pool. DruidAbstractDataSource. ValidateConnection (DruidAbstractDataSource. Java: 1216)
At com. Alibaba. Druid. Pool. DruidAbstractDataSource. CreatePhysicalConnection (DruidAbstractDataSource. Java: 1439)
At com. Alibaba. Druid. Pool. DruidDataSource. Init (DruidDataSource. Java: 618)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 915)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 911)
At com. Alibaba. Druid. Pool. DruidDataSource. GetConnection (DruidDataSource. Java: 98)
The at cn. Itcast. Datasoure. Druid. DruidDemo. Main (DruidDemo. Java: 24)



How to solve?

CodePudding user response:

Url=JDBC: mysql:///first? ServerTimezone=UTC

Here to write a mistake without server

CodePudding user response:

Positive solution # 1,
I am a yml file, so is the url:
Url: JDBC: mysql://localhost: 3306/testdb? serverTimezone=UTC
  • Related