Public Key Retrieval is not allowed解决方法
allowPublicKeyRetrieval=true在配置文件的url后面添加
当然这只是一种连接方式,还可以通过编写德鲁伊连接池的工具类来连接
@Test
public void testdurid() throws Exception {
//1.加入Druid jar包
//2.加入配置文件druid.properties, 将文件拷贝到项目的src目录
//3.创建properties对象 用来读取配置文件
Properties properties = new Properties();
properties.load(new FileInputStream(("src\\druid.properties")));
//4.创建一个指定参数的数据库连接池
DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
Connection connection = dataSource.getConnection();
System.out.println("连接成功");
connection.close();
}
#key=value
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/hsp_db02?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
#url=jdbc:mysql://localhost:3306/girls
username=root
password=root
#initial connection Size
initialSize=10
#min idle connecton size
minIdle=5
#max active connection size
maxActive=50
#max wait time (5000 mil seconds)
maxWait=5000