fine:()修改数据查询参数
parent
cad9c1dd6f
commit
000e11a74e
|
@ -63,13 +63,12 @@ public class DataSourceController {
|
|||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @param connect 实体类
|
||||
* @return 返回试图
|
||||
*/
|
||||
@PostMapping("/dataName")
|
||||
@Operation(summary = "获取数据库名",description = "从数据库中抽取数据库名称")
|
||||
public Result<String[]> extractDataName(@RequestBody Connect connect){
|
||||
String[] tableName = dataSourceService.extractDataName(connect);
|
||||
public Result<String[]> extractDataName(){
|
||||
String[] tableName = dataSourceService.extractDataName();
|
||||
if (StringUtils.isEmpty(tableName)){
|
||||
return Result.success(null,"未查询到结构,请检查数据来源");
|
||||
}
|
||||
|
@ -78,13 +77,12 @@ public class DataSourceController {
|
|||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @param connect 实体类
|
||||
* @return 返回试图
|
||||
*/
|
||||
@PostMapping("/tableName")
|
||||
@Operation(summary = "获取数据库表名",description = "从数据库中抽取数据库表名称")
|
||||
public Result<String[]> extractTableName(@RequestBody Connect connect){
|
||||
String[] tableFIES = dataSourceService.extractTableName(connect);
|
||||
public Result<String[]> extractTableName(){
|
||||
String[] tableFIES = dataSourceService.extractTableName();
|
||||
if (StringUtils.isEmpty(tableFIES)){
|
||||
return Result.success(null,"未查询到结构,请检查数据来源");
|
||||
}
|
||||
|
|
|
@ -30,15 +30,13 @@ public interface DataSourceService extends IService<DataSourceList> {
|
|||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @param connect 实体类
|
||||
* @return 返回试图
|
||||
*/
|
||||
String[] extractDataName(Connect connect);
|
||||
String[] extractDataName();
|
||||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @param connect 实体类
|
||||
* @return 返回试图
|
||||
*/
|
||||
String[] extractTableName(Connect connect);
|
||||
String[] extractTableName();
|
||||
}
|
||||
|
|
|
@ -180,29 +180,14 @@ public class DataSourceServiceImpl
|
|||
|
||||
/**
|
||||
* 获取数据库名
|
||||
* @param connect 实体类
|
||||
* @return 返回试图
|
||||
*/
|
||||
@Override
|
||||
public String[] extractDataName(Connect connect) {
|
||||
|
||||
if (StringUtils.isEmpty(connect.getIpAddress())){
|
||||
throw new RuntimeException("请输入ip地址+端口号! 格式:127.0.0.1:3306");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(connect.getUserName())){
|
||||
throw new RuntimeException("请输入数据库用户名!");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(connect.getPassword())){
|
||||
throw new RuntimeException("请输入数据库密码");
|
||||
}
|
||||
public String[] extractDataName() {
|
||||
|
||||
String sql = null;
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConn(connect);
|
||||
if (StringUtils.isNotEmpty(connect.getTableName())) {
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConnRs();
|
||||
sql = "SHOW DATABASES;";
|
||||
}
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
// 在这里执行你的数据库操作
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
|
@ -228,28 +213,14 @@ public class DataSourceServiceImpl
|
|||
|
||||
/**
|
||||
* 获取数据库表名
|
||||
* @param connect 实体类
|
||||
* @return 返回试图
|
||||
*/
|
||||
@Override
|
||||
public String[] extractTableName(Connect connect) {
|
||||
if (StringUtils.isEmpty(connect.getIpAddress())){
|
||||
throw new RuntimeException("请输入ip地址+端口号! 格式:127.0.0.1:3306");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(connect.getUserName())){
|
||||
throw new RuntimeException("请输入数据库用户名!");
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(connect.getPassword())){
|
||||
throw new RuntimeException("请输入数据库密码");
|
||||
}
|
||||
public String[] extractTableName() {
|
||||
|
||||
String sql = null;
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConn(connect);
|
||||
if (StringUtils.isNotEmpty(connect.getTableName())) {
|
||||
DruidDataSource druidDataSource = JdbcHelper.getConnRs();
|
||||
sql = "SHOW tables;";
|
||||
}
|
||||
try (Connection conn = druidDataSource.getConnection()) {
|
||||
// 在这里执行你的数据库操作
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
|
|
|
@ -43,6 +43,28 @@ public class JdbcHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static DruidDataSource getConnRs() {
|
||||
|
||||
try {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setUrl("jdbc:mysql://21.12.0.10:3306/h6_cloud_server?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){
|
||||
|
|
Loading…
Reference in New Issue