|
@@ -26,11 +26,20 @@ public class DatabaseConnectionMap {
|
|
|
dataSource.setUsername("db_cdyq6tkqn1ioja179i8b");
|
|
|
dataSource.setPassword("By@#5c9i75sgtx3b620g6m6e");
|
|
|
JdbcTemplate template = new JdbcTemplate(dataSource);
|
|
|
-
|
|
|
+ jdbcTemplate = template;
|
|
|
// map中存值
|
|
|
databaseConnectionMap.put(dataBaseName, template);
|
|
|
- return template;
|
|
|
}
|
|
|
+
|
|
|
+ // 测试连接
|
|
|
+ try {
|
|
|
+ int count = jdbcTemplate.queryForObject("SELECT 1 FROM DUAL" , Integer.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 移除连接失败的数据源
|
|
|
+ databaseConnectionMap.remove(dataBaseName);
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
return jdbcTemplate;
|
|
|
}
|
|
|
}
|