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