fine:()重构
parent
000e11a74e
commit
94a9c03f1f
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.common.domain
|
||||
* @Project:cloud-property
|
||||
* @name:dataName
|
||||
* @Date:2024/8/27 19:14
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("data_name")
|
||||
public class DataName {
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
*/
|
||||
private String name;
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package com.muyu.common.domain;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
|
@ -14,18 +16,25 @@ import lombok.experimental.SuperBuilder;
|
|||
* @Date:2024/8/25 15:12
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@com.baomidou.mybatisplus.annotation.TableName("TableNames")
|
||||
public class TableNames extends BaseEntity {
|
||||
@TableName("table_name")
|
||||
public class TableNames {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String[] tableName = new String[20];
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 数据库名称
|
||||
* 数据库名称ID
|
||||
*/
|
||||
private String[] dataName = new String[10];
|
||||
private Integer dataId;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.DataName;
|
||||
import com.muyu.server.service.DataNameService;
|
||||
import com.muyu.server.service.DataSourceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.controller
|
||||
* @Project:cloud-property
|
||||
* @name:DataNameController
|
||||
* @Date:2024/8/27 21:31
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/dataName")
|
||||
@Tag(name = "抽取数据名",description = "从数据源抽取数据名")
|
||||
@AllArgsConstructor
|
||||
public class DataNameController {
|
||||
|
||||
private final DataNameService dataNameService;
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "获取数据库名",description = "从数据库中抽取数据库名称")
|
||||
public Result<List<DataName>> extractDataName(){
|
||||
List<DataName> tableName = dataNameService.extractDataName();
|
||||
if (StringUtils.isEmpty(tableName)){
|
||||
return Result.success(null,"未查询到结构,请检查数据来源");
|
||||
}
|
||||
return Result.success(tableName,"您的数据已成功获取");
|
||||
}
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.Connect;
|
||||
import com.muyu.common.domain.DataSourceList;
|
||||
import com.muyu.common.domain.TableFie;
|
||||
import com.muyu.common.domain.*;
|
||||
import com.muyu.server.service.DataSourceService;
|
||||
import com.muyu.server.service.TableFieldService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -61,32 +59,22 @@ public class DataSourceController {
|
|||
return Result.success(tableFIES,"您的数据已成功获取");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@PostMapping("/dataName")
|
||||
@Operation(summary = "获取数据库名",description = "从数据库中抽取数据库名称")
|
||||
public Result<String[]> extractDataName(){
|
||||
String[] tableName = dataSourceService.extractDataName();
|
||||
if (StringUtils.isEmpty(tableName)){
|
||||
return Result.success(null,"未查询到结构,请检查数据来源");
|
||||
}
|
||||
return Result.success(tableName,"您的数据已成功获取");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@PostMapping("/tableName")
|
||||
@Operation(summary = "获取数据库表名",description = "从数据库中抽取数据库表名称")
|
||||
public Result<String[]> extractTableName(){
|
||||
String[] tableFIES = dataSourceService.extractTableName();
|
||||
if (StringUtils.isEmpty(tableFIES)){
|
||||
return Result.success(null,"未查询到结构,请检查数据来源");
|
||||
}
|
||||
return Result.success(tableFIES,"您的数据已成功获取");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// /**
|
||||
// * 获取数据库表名
|
||||
// * @return 返回试图
|
||||
// */
|
||||
// @PostMapping("/tableName")
|
||||
// @Operation(summary = "获取数据库表名",description = "从数据库中抽取数据库表名称")
|
||||
// public Result<List<TableNames>> extractTableName(){
|
||||
// List<TableNames> tableFIES = dataSourceService.extractTableName();
|
||||
// if (StringUtils.isEmpty(tableFIES)){
|
||||
// return Result.success(null,"未查询到结构,请检查数据来源");
|
||||
// }
|
||||
// return Result.success(tableFIES,"您的数据已成功获取");
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.server.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import com.muyu.server.service.TableRunNameService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.controller
|
||||
* @Project:cloud-property
|
||||
* @name:TableRunNameController
|
||||
* @Date:2024/8/27 20:52
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/tableRunName")
|
||||
@Tag(name = "抽取数据表名",description = "从数据源抽取数据表名")
|
||||
@AllArgsConstructor
|
||||
public class TableRunNameController {
|
||||
|
||||
private final TableRunNameService tableRunNameService;
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@Operation(summary = "获取数据库表名",description = "从数据库中抽取数据库表名称")
|
||||
public Result<List<TableNames>> extractTableName(String name){
|
||||
List<TableNames> tableFIES = tableRunNameService.extractTableName(name);
|
||||
if (StringUtils.isEmpty(tableFIES)){
|
||||
return Result.success(tableFIES,"未查询到结构,请检查数据来源");
|
||||
}
|
||||
return Result.success(tableFIES,"您的数据已成功获取");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.server.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.domain.DataName;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.mapper
|
||||
* @Project:cloud-property
|
||||
* @name:DataNameMapper
|
||||
* @Date:2024/8/27 21:35
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataNameMapper extends BaseMapper<DataName> {
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.server.mapper;
|
||||
|
||||
import com.muyu.common.domain.DataName;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.mapper
|
||||
* @Project:cloud-property
|
||||
* @name:DataRunNameMapper
|
||||
* @Date:2024/8/27 20:01
|
||||
*/
|
||||
@Mapper
|
||||
public interface DataRunNameMapper {
|
||||
void addDataRunName(@Param("list") ArrayList<DataName> list);
|
||||
|
||||
void addTableRunName(@Param("tableNames1") List<TableNames> tableNames1);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.server.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.domain.CoreDataList;
|
||||
import com.muyu.common.domain.DataName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.service
|
||||
* @Project:cloud-property
|
||||
* @name:DataNameService
|
||||
* @Date:2024/8/27 21:34
|
||||
*/
|
||||
public interface DataNameService extends IService<DataName> {
|
||||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @return 返回试图
|
||||
*/
|
||||
List<DataName> extractDataName();
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.server.service;
|
||||
|
||||
import com.muyu.common.domain.DataName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.service
|
||||
* @Project:cloud-property
|
||||
* @name:DataRunName
|
||||
* @Date:2024/8/27 20:00
|
||||
*/
|
||||
public interface DataRunNameService {
|
||||
/**
|
||||
* 添加数据库
|
||||
* @param list
|
||||
*/
|
||||
void addDataRunName(ArrayList<DataName> list);
|
||||
}
|
|
@ -2,9 +2,7 @@ package com.muyu.server.service;
|
|||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.domain.Connect;
|
||||
import com.muyu.common.domain.DataSourceList;
|
||||
import com.muyu.common.domain.TableFie;
|
||||
import com.muyu.common.domain.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -28,15 +26,6 @@ public interface DataSourceService extends IService<DataSourceList> {
|
|||
*/
|
||||
List<TableFie> extractTableField(Connect connect);
|
||||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @return 返回试图
|
||||
*/
|
||||
String[] extractDataName();
|
||||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @return 返回试图
|
||||
*/
|
||||
String[] extractTableName();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.server.service;
|
||||
|
||||
import com.muyu.common.domain.TableNames;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.service
|
||||
* @Project:cloud-property
|
||||
* @name:TableRunNameService
|
||||
* @Date:2024/8/27 20:49
|
||||
*/
|
||||
public interface TableRunNameService {
|
||||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @return 返回试图
|
||||
*/
|
||||
List<TableNames> extractTableName(String name);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.server.service.impl;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.domain.DataName;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import com.muyu.server.mapper.DataNameMapper;
|
||||
import com.muyu.server.service.DataNameService;
|
||||
import com.muyu.server.util.JdbcHelper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.service.impl
|
||||
* @Project:cloud-property
|
||||
* @name:DataNameServiceImpl
|
||||
* @Date:2024/8/27 21:35
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class DataNameServiceImpl
|
||||
extends ServiceImpl<DataNameMapper,DataName>
|
||||
implements DataNameService {
|
||||
|
||||
private final DataNameService dataNameService;
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@Override
|
||||
public List<DataName> extractDataName() {
|
||||
|
||||
|
||||
dataNameService.extractDataName();
|
||||
String sql = null;
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConnRs();
|
||||
sql = "SHOW DATABASES;";
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
// 在这里执行你的数据库操作
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
TableNames tableNames = new TableNames();
|
||||
|
||||
ArrayList<DataName> list = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String database = rs.getString("Database");
|
||||
list.add(new DataName(0,database));
|
||||
}
|
||||
JdbcHelper.close(conn,preparedStatement,rs);
|
||||
dataRunNameService.addDataRunName(list);
|
||||
return list;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.server.service.impl;
|
||||
|
||||
import com.muyu.common.domain.DataName;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import com.muyu.server.mapper.DataRunNameMapper;
|
||||
import com.muyu.server.service.DataRunNameService;
|
||||
import com.muyu.server.service.DataSourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.service.impl
|
||||
* @Project:cloud-property
|
||||
* @name:DataRunNameImpl
|
||||
* @Date:2024/8/27 20:01
|
||||
*/
|
||||
@Service
|
||||
public class DataRunNameServiceImpl implements DataRunNameService {
|
||||
|
||||
@Autowired
|
||||
private DataRunNameMapper dataRunNameMapper;
|
||||
@Autowired
|
||||
private TableRunNameServiceImpl tableRunNameService;
|
||||
@Override
|
||||
public void addDataRunName(ArrayList<DataName> list) {
|
||||
|
||||
dataRunNameMapper.addDataRunName(list);
|
||||
List<TableNames> tableNames1 = null;
|
||||
for (DataName dataName : list) {
|
||||
tableNames1 = tableRunNameService.extractTableName(dataName.getName());
|
||||
for (TableNames tableNames : tableNames1) {
|
||||
tableNames.setDataId(dataName.getId());
|
||||
}
|
||||
System.out.println(dataName.getId());
|
||||
}
|
||||
|
||||
dataRunNameMapper.addTableRunName(tableNames1);
|
||||
}
|
||||
}
|
|
@ -4,11 +4,9 @@ import com.alibaba.druid.pool.DruidDataSource;
|
|||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.domain.Connect;
|
||||
import com.muyu.common.domain.DataSourceList;
|
||||
import com.muyu.common.domain.TableFie;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import com.muyu.common.domain.*;
|
||||
import com.muyu.server.mapper.DataSourceMapper;
|
||||
import com.muyu.server.service.DataRunNameService;
|
||||
import com.muyu.server.service.DataSourceService;
|
||||
import com.muyu.server.service.TableFieldService;
|
||||
import com.muyu.server.util.JdbcHelper;
|
||||
|
@ -34,7 +32,7 @@ public class DataSourceServiceImpl
|
|||
extends ServiceImpl<DataSourceMapper, DataSourceList>
|
||||
implements DataSourceService {
|
||||
@Autowired
|
||||
private TableFieldService tableFieldService;
|
||||
private DataRunNameService dataRunNameService;
|
||||
|
||||
@Override
|
||||
public List<DataSourceList> extractData(Connect connect) {
|
||||
|
@ -64,14 +62,6 @@ public class DataSourceServiceImpl
|
|||
String sql = null;
|
||||
DruidDataSource conn = JdbcHelper.getConn(connect);
|
||||
String like = "";
|
||||
// for (String s : connect.getLike()) {
|
||||
// if (s.equals("Name") || s.equals("name")){
|
||||
// like += ",dashuju." + "`\uFEFFName`";
|
||||
// }else{
|
||||
// like += "," + s;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
String substring = like.substring(1);
|
||||
if (StringUtils.isNotEmpty(connect.getTableName())) {
|
||||
sql = "select " + substring + " from " + connect.getTableName() +" LIMIT "+i+","+size;
|
||||
|
@ -178,68 +168,5 @@ public class DataSourceServiceImpl
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@Override
|
||||
public String[] extractDataName() {
|
||||
|
||||
String sql = null;
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConnRs();
|
||||
sql = "SHOW DATABASES;";
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
// 在这里执行你的数据库操作
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
TableNames tableNames = new TableNames();
|
||||
int count = 0;
|
||||
String[] dataName = tableNames.getDataName();
|
||||
while (rs.next()) {
|
||||
String database = rs.getString("Database");
|
||||
System.out.println(database);
|
||||
dataName[count] = database;
|
||||
count++;
|
||||
System.out.println(tableNames);
|
||||
}
|
||||
JdbcHelper.close(conn,preparedStatement,rs);
|
||||
return tableNames.getDataName();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@Override
|
||||
public String[] extractTableName() {
|
||||
|
||||
String sql = null;
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConnRs();
|
||||
sql = "SHOW tables;";
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
// 在这里执行你的数据库操作
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
TableNames tableNames = new TableNames();
|
||||
int count = 0;
|
||||
while (rs.next()) {
|
||||
String tables = rs.getString("Tables_in_core_data_warehouse");
|
||||
|
||||
tableNames.getTableName()[count] = tables;
|
||||
count++;
|
||||
System.out.println(tableNames);
|
||||
}
|
||||
JdbcHelper.close(conn,preparedStatement,rs);
|
||||
return tableNames.getTableName();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.muyu.server.service.impl;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.muyu.common.domain.TableNames;
|
||||
import com.muyu.server.service.TableRunNameService;
|
||||
import com.muyu.server.util.JdbcHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:yang
|
||||
* @Package:com.muyu.server.service
|
||||
* @Project:cloud-property
|
||||
* @name:TableRunNameServiceImpl
|
||||
* @Date:2024/8/27 20:50
|
||||
*/
|
||||
@Service
|
||||
public class TableRunNameServiceImpl implements TableRunNameService {
|
||||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @return 返回试图
|
||||
*/
|
||||
@Override
|
||||
public List<TableNames> extractTableName(String name) {
|
||||
|
||||
String sql = null;
|
||||
DruidDataSource druidDataSource = JdbcHelper.getDataConnRs(name);
|
||||
sql = "SHOW tables;";
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
// 在这里执行你的数据库操作
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
TableNames tableNames = new TableNames();
|
||||
ArrayList<TableNames> list = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String tables = rs.getString("Tables_in_core_data_warehouse");
|
||||
list.add(new TableNames(0,tables,0));
|
||||
}
|
||||
JdbcHelper.close(conn,preparedStatement,rs);
|
||||
|
||||
return list;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -65,6 +65,28 @@ public class JdbcHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static DruidDataSource getDataConnRs(String name) {
|
||||
|
||||
try {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl("jdbc:mysql://21.12.0.10:3306/"+name+"?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
|
||||
druidDataSource.setUsername("root");
|
||||
druidDataSource.setPassword("Bwie-8666");
|
||||
//"com.mysql.cj.jdbc.Driver"
|
||||
druidDataSource.setDriverClassName(new ConnectReq().getDRIVER());
|
||||
// druidDataSource.setInitialSize(connect.getInitSize());
|
||||
// druidDataSource.setMaxActive(connect.getMaxNumConn());
|
||||
// druidDataSource.setMaxWait(connect.getMaxWaitTime());
|
||||
|
||||
return druidDataSource;
|
||||
} catch (Exception e) {
|
||||
log.error("异常为:{}"+e);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void close(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet) throws SQLException {
|
||||
|
||||
if (null != connection){
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.DataRunNameMapper">
|
||||
|
||||
<insert id="addDataRunName" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO
|
||||
`core_data_warehouse`.`data_name`
|
||||
( `name`)
|
||||
VALUES
|
||||
<foreach collection="list" item="init" separator=",">
|
||||
( #{init.name})
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="addTableRunName">
|
||||
INSERT INTO `core_data_warehouse`.`table_name`
|
||||
( `name`, `data_id`)
|
||||
VALUES
|
||||
<foreach collection="tableNames1" item="init" separator=",">
|
||||
( #{init.name},#{init.dataId})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -69,3 +69,29 @@
|
|||
11:48:56.830 [SpringApplicationShutdownHook] INFO c.a.d.p.DruidDataSource - [close,2277] - {dataSource-1} closed
|
||||
11:48:56.830 [SpringApplicationShutdownHook] INFO c.b.d.d.d.DefaultDataSourceDestroyer - [destroy,98] - dynamic-datasource close the datasource named [master] success,
|
||||
11:48:56.830 [SpringApplicationShutdownHook] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,219] - dynamic-datasource all closed success,bye
|
||||
20:39:18.304 [main] INFO c.m.s.IntegrationApplication - [logStartupProfileInfo,660] - The following 1 profile is active: "dev"
|
||||
20:39:21.410 [main] INFO o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
|
||||
20:39:21.410 [main] INFO o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/10.1.24]
|
||||
20:39:21.490 [main] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
|
||||
20:39:23.065 [main] INFO c.a.d.p.DruidDataSource - [init,1002] - {dataSource-1,master} inited
|
||||
20:39:23.067 [main] INFO c.b.d.d.DynamicRoutingDataSource - [addDataSource,158] - dynamic-datasource - add a datasource named [master] success
|
||||
20:39:23.067 [main] INFO c.b.d.d.DynamicRoutingDataSource - [afterPropertiesSet,241] - dynamic-datasource initial loaded [1] datasource,primary datasource named [master]
|
||||
20:39:23.583 [main] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,215] - dynamic-datasource start closing ....
|
||||
20:39:23.585 [main] INFO c.a.d.p.DruidDataSource - [close,2204] - {dataSource-1} closing ...
|
||||
20:39:23.593 [main] INFO c.a.d.p.DruidDataSource - [close,2277] - {dataSource-1} closed
|
||||
20:39:23.593 [main] INFO c.b.d.d.d.DefaultDataSourceDestroyer - [destroy,98] - dynamic-datasource close the datasource named [master] success,
|
||||
20:39:23.593 [main] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,219] - dynamic-datasource all closed success,bye
|
||||
20:39:23.594 [main] INFO o.a.c.c.StandardService - [log,173] - Stopping service [Tomcat]
|
||||
20:41:14.717 [main] INFO c.m.s.IntegrationApplication - [logStartupProfileInfo,660] - The following 1 profile is active: "dev"
|
||||
20:41:17.296 [main] INFO o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
|
||||
20:41:17.298 [main] INFO o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/10.1.24]
|
||||
20:41:17.375 [main] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
|
||||
20:41:19.332 [main] INFO c.a.d.p.DruidDataSource - [init,1002] - {dataSource-1,master} inited
|
||||
20:41:19.333 [main] INFO c.b.d.d.DynamicRoutingDataSource - [addDataSource,158] - dynamic-datasource - add a datasource named [master] success
|
||||
20:41:19.333 [main] INFO c.b.d.d.DynamicRoutingDataSource - [afterPropertiesSet,241] - dynamic-datasource initial loaded [1] datasource,primary datasource named [master]
|
||||
20:41:19.779 [main] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,215] - dynamic-datasource start closing ....
|
||||
20:41:19.780 [main] INFO c.a.d.p.DruidDataSource - [close,2204] - {dataSource-1} closing ...
|
||||
20:41:19.785 [main] INFO c.a.d.p.DruidDataSource - [close,2277] - {dataSource-1} closed
|
||||
20:41:19.785 [main] INFO c.b.d.d.d.DefaultDataSourceDestroyer - [destroy,98] - dynamic-datasource close the datasource named [master] success,
|
||||
20:41:19.786 [main] INFO c.b.d.d.DynamicRoutingDataSource - [destroy,219] - dynamic-datasource all closed success,bye
|
||||
20:41:19.787 [main] INFO o.a.c.c.StandardService - [log,173] - Stopping service [Tomcat]
|
||||
|
|
Loading…
Reference in New Issue