@PostConstruct
private void init(){
logger.info("开始初始化oracle数据源");
String oracleJdbcUrl = ContextUtil.getMsgByKey("Oracle_JDBC_URL");
String oracleJdbcUser = ContextUtil.getMsgByKey("Oracle_JDBC_USER");
String oracleJdbcPassword = ContextUtil.getMsgByKey("Oracle_JDBC_PASSWORD");
String oracleJdbcDriver = ContextUtil.getMsgByKey("Oracle_JDBC_DRIVER");
if (StringUtils.isAnyBlank(oracleJdbcPassword, oracleJdbcUrl, oracleJdbcUser,oracleJdbcDriver)) {
logger.warn("无法获取oracle参数,将无法同步数据");
}
Properties properties = new Properties();
properties.setProperty("driverClassName",oracleJdbcDriver);
properties.setProperty("url",oracleJdbcUrl);
properties.setProperty("username",oracleJdbcUser);
properties.setProperty("password",oracleJdbcPassword);
try {
this.oracleDataSource = DruidDataSourceFactory.createDataSource(properties);
} catch (Exception e) {
logger.info("初始化oracle数据源异常,将无法同步数据");
e.printStackTrace();
}
try {
ClassPathResource rc = new ClassPathResource("syn-asset.sql", KjXmService.class);
EncodedResource er = new EncodedResource(rc, "utf-8");
Connection connection = oracleDataSource.getConnection();
if (connection.isValid(1000)){
logger.info("oracle数据源初始化成功");
}else {
logger.warn("oracle数据源初始化失败");
}
ScriptUtils.executeSqlScript(connection,er);
DataSourceUtils.releaseConnection(connection,oracleDataSource);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("success");
}
简单的数据库脚本执行工具-笔记
最新推荐文章于 2024-06-24 09:56:11 发布