提交 e28c911f authored 作者: mry's avatar mry

fix(base): 执行器部分包裹了try catch

上级 1c7070a2
...@@ -83,17 +83,21 @@ public class SqlController { ...@@ -83,17 +83,21 @@ public class SqlController {
return ResponseEntity.ok(jdbcTemplate.queryForList(GET_ALL_TABLES)); return ResponseEntity.ok(jdbcTemplate.queryForList(GET_ALL_TABLES));
} }
@GetMapping("/hints") @GetMapping("/hints")
@ApiOperation("获得数据库的语法提示") @ApiOperation("获得数据库的语法提示")
public ResponseEntity<List<GrammarTable>> getDbHints(@RequestParam Long connectId) { public ResponseEntity<List<GrammarTable>> getDbHints(@RequestParam Long connectId) {
String tableSql = "SELECT a.table_name tableName,a.table_comment tableDes,b.COLUMN_NAME fieldName,b.column_comment fieldDes,b.column_type fieldType FROM information_schema. TABLES a LEFT JOIN information_schema. COLUMNS b ON a.table_name = b.TABLE_NAME WHERE a.table_schema = '%s' ORDER BY a.table_name"; String tableSql = "SELECT a.table_name tableName,a.table_comment tableDes,b.COLUMN_NAME fieldName,b.column_comment fieldDes,b.column_type fieldType FROM information_schema. TABLES a LEFT JOIN information_schema. COLUMNS b ON a.table_name = b.TABLE_NAME WHERE a.table_schema = '%s' ORDER BY a.table_name";
// 切换数据源,执行SQL // 切换数据源,执行SQL
DataSourceDTO dataSourceDTO = Optional.ofNullable(connectService.getById(connectId)) try {
.orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的连接池connect对象", connectId))) DataSourceDTO dataSourceDTO = Optional.ofNullable(connectService.getById(connectId))
.toDataSourceDTO(); .orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的连接池connect对象", connectId)))
Set<String> dataSources = dataSourceService.switchDataSource(dataSourceDTO); .toDataSourceDTO();
log.info("当前使用的的数据源 {}", dataSourceService.peek()); Set<String> dataSources = dataSourceService.switchDataSource(dataSourceDTO);
log.info("当前使用的的数据源 {}", dataSourceService.peek());
} catch (Exception e) {
e.printStackTrace();
throw new GlobalException("数据库连接失败或表不存在");
}
String databaseName = jdbcTemplate.queryForList("select database();").get(0).get("database()").toString(); String databaseName = jdbcTemplate.queryForList("select database();").get(0).get("database()").toString();
tableSql = String.format(tableSql, databaseName); tableSql = String.format(tableSql, databaseName);
List<GrammarTable> grammarTables = new GrammarTable().trans2Table(jdbcTemplate.queryForList(tableSql)); List<GrammarTable> grammarTables = new GrammarTable().trans2Table(jdbcTemplate.queryForList(tableSql));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论