this is the project architecture, which is a simple console test to connect to the mysql database
this is the configuration file
jdbcUrl = jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8
user = root
password = 123456
dataSource.cachePrepStmts = true
dataSource.prepStmtCacheSize = 250
dataSource.prepStmtCacheSqlLimit = 2048
dataSource.useServerPrepStmts = true
dataSource.useLocalSessionState = true
dataSource.useLocalTransactionState=true
dataSource.rewriteBatchedStatements = true
dataSource.cacheResultSetMetadata = true
dataSource.cacheServerConfiguration = true
dataSource.elideSetAutoCommits = true
dataSource.maintainTimeStats = dataSource.maintainTimeStats
this is the code to test the connection
import java.sql.Connection;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class HikariPoolManager {
static Logger logger = LogManager.getLogger();
static HikariConfig config = new HikariConfig("/hurik.properties");
static HikariDataSource ds = new HikariDataSource(config);
/**
*
*
* @return
* @throws Exception
*/
public static Connection getConnection() throws Exception {
Connection connection = null;
try {
connection = ds.getConnection();
} catch (Exception e) {
logger.error("!" + e);
throw e;
}
return connection;
}
/**
*
*
* @param connection
* @throws Exception
*/
public static void freeConnection(Connection connection) throws Exception {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
logger.error("!" + e.getMessage());
}
}
}
public static void main(String[] args) throws Exception {
System.out.println(ds.getConnection());
}
}
Runtime error:
ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property "log4j2.debug" to show Log4j 2 internal initialization logging. See https://logging.apache.org/lo. for instructions on how to configure Log4j 2
SLF4J: Failed to load class" org.slf4j.impl.StaticLoggerBinder ".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes .ht. for further details.
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Property user does not exist on target class com.zaxxer.hikari.HikariConfig
at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:131)
at com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties$0(PropertyElf.java:57)
at java.util.Hashtable.forEach(Unknown Source)
at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:52)
at com.zaxxer.hikari.HikariConfig.loadProperties(HikariConfig.java:1067)
at com.zaxxer.hikari.HikariConfig.<init>(HikariConfig.java:148)
at HikariPoolManager.<clinit>(HikariPoolManager.java:11)
did not find a useful solution on the Internet, hope to get your help, or send a simple, complete and successful demo case