Skip to content

Commit

Permalink
be
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed May 21, 2024
1 parent 62e7659 commit 5a93f2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/main/java/com/rebuild/core/support/setup/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
import java.util.Properties;
import java.util.TimeZone;

import static com.rebuild.core.support.ConfigurationItem.*;
import static com.rebuild.core.support.ConfigurationItem.CacheHost;
import static com.rebuild.core.support.ConfigurationItem.CachePassword;
import static com.rebuild.core.support.ConfigurationItem.CachePort;

/**
* 系统安装
Expand Down Expand Up @@ -227,9 +229,10 @@ public Connection getConnection(String dbName) throws SQLException {
try {
return DriverManager.getConnection(
props.getProperty("db.url"), props.getProperty("db.user"), props.getProperty("db.passwd"));

} catch (SQLException ex) {
allowPublicKeyRetrieval = ex.getLocalizedMessage().contains("Public Key Retrieval is not allowed");

// Plugin 'mysql_native_password' is not loaded
allowPublicKeyRetrieval = ex.getMessage().contains("Public Key Retrieval is not allowed");
if (allowPublicKeyRetrieval) {
props = buildConnectionProps(dbName);
return DriverManager.getConnection(
Expand Down Expand Up @@ -306,7 +309,7 @@ protected boolean installDatabase() {
try (Connection ignored = getConnection(null)) {
// NOOP
} catch (SQLException e) {
if (!e.getLocalizedMessage().contains("Unknown database")) {
if (!e.getMessage().contains("Unknown database")) {
throw new SetupException(e);
}

Expand All @@ -328,9 +331,9 @@ protected boolean installDatabase() {
// 初始化数据库
try (Connection conn = getConnection(null)) {
int affetced = 0;
for (final String sql : getDbInitScript()) {
for (final String s : getDbInitScript()) {
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
stmt.execute(s);
affetced++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public RespBody testConnection(HttpServletRequest request) {
return RespBody.ok(okMsg);

} catch (SQLException ex) {
if (ex.getLocalizedMessage().contains("Unknown database")) {
if (ex.getMessage().contains("Unknown database")) {
String okMsg = Language.L("连接成功 : 数据库 **%s** 不存在,系统将自动创建", dbProps.getString("dbName"));
return RespBody.ok(okMsg);
} else {
Expand Down

0 comments on commit 5a93f2f

Please sign in to comment.