use of com.zrlog.common.type.TestConnectDbResult in project zrlog by 94fzb.
the class InstallController method testDbConn.
/**
* 检查数据库是否可以正常连接使用,无法连接时给出相应的提示
*/
public void testDbConn() {
Map<String, String> dbConn = new HashMap<>();
dbConn.put("jdbcUrl", "jdbc:mysql://" + getPara("dbhost") + ":" + getPara("port") + "/" + getPara("dbname") + "?&characterEncoding=UTF-8");
dbConn.put("user", getPara("dbuser"));
dbConn.put("password", getPara("dbpwd"));
dbConn.put("driverClass", "com.mysql.jdbc.Driver");
JFinal.me().getServletContext().setAttribute("dbConn", dbConn);
TestConnectDbResult testConnectDbResult = new InstallService(PathKit.getWebRootPath() + "/WEB-INF", dbConn).testDbConn();
if (testConnectDbResult.getError() != 0) {
setAttr("errorMsg", "[Error-" + testConnectDbResult.getError() + "] - " + I18NUtil.getStringFromRes("connectDbError_" + testConnectDbResult.getError()));
index();
} else {
render("/install/message.jsp");
}
}
use of com.zrlog.common.type.TestConnectDbResult in project zrlog by 94fzb.
the class InstallService method testDbConn.
/**
* 尝试使用填写的数据库信息连接数据库
*/
public TestConnectDbResult testDbConn() {
TestConnectDbResult testConnectDbResult = null;
try {
Connection connection = getConnection();
connection.close();
testConnectDbResult = TestConnectDbResult.SUCCESS;
} catch (ClassNotFoundException e) {
LOGGER.error("", e);
testConnectDbResult = TestConnectDbResult.MISSING_MYSQL_DRIVER;
} catch (MySQLSyntaxErrorException e) {
LOGGER.error("", e);
if (e.getMessage().contains("Access denied for user ")) {
testConnectDbResult = TestConnectDbResult.DB_NOT_EXISTS;
}
} catch (SQLException e) {
LOGGER.error("", e);
if (e.getCause() instanceof ConnectException) {
testConnectDbResult = TestConnectDbResult.CREATE_CONNECT_ERROR;
} else {
testConnectDbResult = TestConnectDbResult.USERNAME_OR_PASSWORD_ERROR;
}
} catch (Exception e) {
LOGGER.error("", e);
testConnectDbResult = TestConnectDbResult.UNKNOWN;
}
return testConnectDbResult;
}
Aggregations