Use DataSourc to get database connection report java.sql.SQLException: Access denied for user''@'localhost' (using password: NO)

Error message

java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)

the reason

The reason is that we did not pass in or did not configure the username and password of the database . When I started to write springboot using JDBC to obtain the connection object, the reason for this error is that

Insert picture description here
I actually use data-username and data-password to connect to the database. I blame myself for not being good at learning. Don't laugh, yes, just say you. Be serious. Just change it to the following picture later.
Insert picture description here
My test code:

@SpringBootTest
class SpringBootDataJdbcApplicationTests {
    
    

    @Autowired
    DataSource dataSource;

    @Test
    void contextLoads() throws SQLException {
    
    
    	// com.zaxxer.hikari.HikariDataSource
        System.out.println(dataSource.getClass());
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        // 关闭连接
        connection.close();
    }

}

Guess you like

Origin blog.csdn.net/qq_47768542/article/details/110957234