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
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.
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();
}
}