1. Error information
Feb 02, 2022 10:44:44 AM com.alibaba.druid.pool.DruidDataSource error
WARNING: init datasource error, url: jdbc:mysql://localhost:3306/xuesheng?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1570)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:874)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1246)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1242)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:89)
at com.qzxiaofeng.jdbc.DruidDemo.main(DruidDemo.java:21)
Feb 02, 2022 10:44:44 AM com.alibaba.druid.pool.DruidDataSource error
WARNING: {dataSource-1} init error
java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1570)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:874)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1246)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1242)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:89)
at com.qzxiaofeng.jdbc.DruidDemo.main(DruidDemo.java:21)
Feb 02, 2022 10:44:44 AM com.alibaba.druid.pool.DruidDataSource info
WARNING: {dataSource-1} inited
Exception in thread "main" java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1570)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1636)
at com.alibaba.druid.pool.DruidDataSource.init(DruidDataSource.java:874)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1246)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1242)
at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:89)
at com.qzxiaofeng.jdbc.DruidDemo.main(DruidDemo.java:21)
II My configuration is as follows
1 Test code
public class DruidDemo {
public static void main(String[] args) throws Exception {
//3.Load the configuration file
Properties prop=new Properties();
prop.load(new FileInputStream("src/druid.properties"));
//4. Get the connection pool object
DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
//5. Get the corresponding database connection
Connection connection = dataSource.getConnection();
System.out.println(connection);
// System.out.println(System.getProperty("user.dir"));
}
}
2. Configuration of guide package in maven
<!-- druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
3.druid.properties configuration
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/xuesheng?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
user=root
password=123456
# initialize the number of connections
initialSize=5
#Maximum number of connections
maxActive=10
#Maximum waiting time
maxWait=3000
3. Solution
Change the user to username in druid.properties
Read More:
- [Solved] com.alibaba.druid.filter.FilterManager : load filter error, filter not found : sl4j
- Configuration of springboot + Druid connection pool
- springboot sqlserver druid reward: validateConnection false
- [Solved] mybatis Error querying database. Cause: java.sql.SQLException: The server time zone value
- [Solved] Failed toString() invocation on an object com.alibaba.fastjson.JSONException: write javaBean error
- [Solved] Sprintboot hikari initialize error: ERROR 27468 — [nio-8080-exec-1] com.zaxxer.hikari.pool.HikariPoolHikariPool
- [Solved] com.alibaba.fastjson.JSONException: syntax error, pos 1, json
- [Solved] java.sql.SQLException: Unsupported character encoding ‘utf-8
- [Solved] nacos Error: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance
- [Solved] Spring integrates canal to call feign error: pool-1-thread-1
- [Solved] Error updating database. Cause: java.sql.SQLException: Incorrect integer value: ‘**‘ for column
- [Solved] fragment error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}…
- [Solved] JAVA Operate Database Error: You have an error in your SQL syntax; Dao layer SQL statement error
- Java uses single thread pool to realize multi thread sequential execution (non alternating, non synchronous)
- [Solved] springboot Project Run Error: HikariPool-1 – Exception during pool initialization.
- [Solved] Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException
- Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is no
- [Solved] Error updating database. Cause: java.sql.SQLException: Unknown initial character set index ‘255‘ re
- Error querying database.Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource.
- JAVA Connect MYSQL Error: Path does not chain with any of the trust anchors