我是用Druid连接数据库,发现数据库偶尔断掉后就不正常了,我采用的是从数据库中读取配置,然后加载Dao的方式,
如果已经初始化则从hm从获取。
Properties properties=new Properties();
try {
properties.put("url", url);
properties.put("username", username);
properties.put("password", password);
properties.put("validationQuery", validationQuery);
properties.put("initialSize", "10");
properties.put("maxActive", "50");
properties.put("testOnBorrow", "false");
properties.put("testOnReturn", "false");
properties.put("testWhileIdle", "true");
properties.put("timeBetweenEvictionRunsMillis", "3000");//配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
Dao dao=new NutDao(DruidDataSourceFactory.createDataSource(properties));
hm.put(name, dao);
return dao;
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
具体错误如下:
com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1863)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
不知道还要配置什么项才不会报错?
添加回复
请先登陆