|
@@ -8,7 +8,6 @@ import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
|
-import java.sql.SQLSyntaxErrorException;
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Map.Entry;
|
|
import java.util.Map.Entry;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
@@ -137,28 +136,33 @@ public class DataSourceUtils {
|
|
|
PreparedStatement preparedStatement = null;
|
|
PreparedStatement preparedStatement = null;
|
|
|
ResultSet resultSet = null;
|
|
ResultSet resultSet = null;
|
|
|
try {
|
|
try {
|
|
|
- logger.info("mainMaster.getConnection...");
|
|
|
|
|
|
|
+ logger.info("mainMaster.getConnection..." + mainMaster.getUsername() + "," + userName);
|
|
|
connection = mainMaster.getConnection();
|
|
connection = mainMaster.getConnection();
|
|
|
- logger.info("mainMaster.getConnection done...");
|
|
|
|
|
- // 根据当前账套用户名获取其数据库配置信息
|
|
|
|
|
- String sql = "select * from master where MA_USER = ?";
|
|
|
|
|
|
|
+ logger.info("mainMaster.getConnection done..." + mainMaster.getUsername() + "," + userName);
|
|
|
|
|
+ // 先检查是否存在MASTER表
|
|
|
|
|
+ String sql = "select count(*) from user_tables where table_name='MASTER'";
|
|
|
preparedStatement = connection.prepareStatement(sql);
|
|
preparedStatement = connection.prepareStatement(sql);
|
|
|
- preparedStatement.setString(1, userName);
|
|
|
|
|
- try {
|
|
|
|
|
- resultSet = preparedStatement.executeQuery();
|
|
|
|
|
- } catch (SQLSyntaxErrorException e) {
|
|
|
|
|
- // 并不是每个数据源都有MA_USER表,因此,出现异常,返回空,紧接着遍历下一个数据源
|
|
|
|
|
|
|
+ resultSet = preparedStatement.executeQuery();
|
|
|
|
|
+ resultSet.next();
|
|
|
|
|
+ // 并不是每个数据源都有MA_USER表,如果不存在,紧接着遍历下一个数据源
|
|
|
|
|
+ if (resultSet.getInt(1) == 0) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
- if (resultSet.next()) {
|
|
|
|
|
|
|
+ preparedStatement.close();
|
|
|
|
|
+ resultSet.close();
|
|
|
|
|
+
|
|
|
|
|
+ // 根据当前账套用户名获取其数据库配置信息
|
|
|
|
|
+ sql = "select * from master where MA_USER = ?";
|
|
|
|
|
+ preparedStatement = connection.prepareStatement(sql);
|
|
|
|
|
+ preparedStatement.setString(1, userName);
|
|
|
|
|
+ resultSet = preparedStatement.executeQuery();
|
|
|
|
|
+ if (resultSet.next() && !StringUtils.isEmpty(resultSet.getString("MS_PWD"))) {
|
|
|
String password = resultSet.getString("MS_PWD");
|
|
String password = resultSet.getString("MS_PWD");
|
|
|
- if (!StringUtils.isEmpty(password)) {
|
|
|
|
|
- // 除了用户名、密码,其他属性一样
|
|
|
|
|
- DruidDataSource result = mainMaster.cloneDruidDataSource();
|
|
|
|
|
- result.setUsername(userName);
|
|
|
|
|
- result.setPassword(password);
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 除了用户名、密码,其他属性一样
|
|
|
|
|
+ DruidDataSource result = mainMaster.cloneDruidDataSource();
|
|
|
|
|
+ result.setUsername(userName);
|
|
|
|
|
+ result.setPassword(password);
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new ReportException(e).setDetailedMessage(e);
|
|
throw new ReportException(e).setDetailedMessage(e);
|