@Override
public void tesDb() {
List<Map<String, String>> maps = mapper.tableSchema();
Map<String, String> m = new LinkedHashMap<>();
String sql="\tselect\n" +
"\t\t\t\tsj.id,\n" +
"\t\t\tsf.file_name fileName,sf.file_path filePath,\n" +
"\t\t\tifnull(sj.spend_time,0) spendTime,sj.create_time createTime\n" +
"\t\tfrom sys_job_log sj left join sys_file sf on sj.log = sf.id\n" +
"\t\t\t\t\t\t\tinner join sys_job job on sj.job = job.id\n" +
"\t\twhere job.name = '银行流水读取' and sj.create_time>'2022-12-10'\n" +
"\t\torder by sj.id desc limit 1 ";
for (Map<String, String> map : maps) {
String tableSchema = map.get("table_schema");
//Map<String, String> db = mapper.db(tableSchema);
try (
Connection conn = getConnection(tableSchema)) {
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
BeanListHandler<dbC> beanListHandler = new BeanListHandler<>(dbC.class);
// BeanListHandler<TablesAndColumnsVo> beanListHandler = new BeanListHandler<>(TablesAndColumnsVo.class);
List<dbC> v = beanListHandler.handle(resultSet);
if(!v.isEmpty()){
m.put(tableSchema, v.get(0).getSpendTime());
}
} catch (SQLException e) {
throw new RuntimeException("获取信息失败:" + e.getMessage());
}
}
System.err.println(m);
}
private String getConnectionUrl(String dbName) {
String url = "jdbc:mysql://XXX/" + dbName
+ "?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=false";
return url;
}
public Connection getConnection(String db) {
String url = getConnectionUrl(db);
try {
Properties p = new Properties();
p.setProperty("user","XXX" );
p.setProperty("password","XX" );
p.setProperty("remarks", "true");
p.setProperty("useInformationSchema", "true");
return DriverManager.getConnection(url, p);
} catch (SQLException e) {
throw new RuntimeException("连接失败" + e.getMessage());
}
}
【JDBC】使用jdbc循环查各个租库数据
最新推荐文章于 2023-05-22 20:47:23 发布