MySQL Inno Setup 中的查询
MySQL query in Inno Setup
在知道 Inno Setup used IzPack 执行我的安装程序之前,由于需要验证即将创建的服务的端口是否正在使用,使用驱动程序查询数据库 jdbc,因此如果连接有效,则发送错误消息以更改端口。
所以这是我以前做的方法,但我不知道如何在 Inno Setup 中做:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection(
"jdbc:mysql://" + server + ":" + port + "/database", "root", password);
if (conn.isValid(0)) {
error = "A server-type installation already exists in: " + server;
return Status.ERROR;
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
}
非常感谢。
您将必须执行命令行 MySQL 客户端 (mysql
)。
有关执行可执行文件和检查其退出代码 and/or 检查其输出的一些示例,请参阅:
- Using Process Exit code to show error message for a specific File in [Run];
- How to get an output of an Exec'ed program in Inno Setup?
找到了一种从答案中发现端口的简单方法 How to check if port is usable in Inno Setup?
function CheckPortOccupied(Port:String):Boolean;
var
ResultCode: Integer;
begin
Exec(ExpandConstant('{cmd}'), '/C netstat -na | findstr'+' /C:":'+Port+' "', '', 0,
ewWaitUntilTerminated, ResultCode);
if ResultCode <> 1 then
begin
Log('this port('+Port+') is occupied');
Result := True;
end
else
begin
Result := False;
end;
end;
在知道 Inno Setup used IzPack 执行我的安装程序之前,由于需要验证即将创建的服务的端口是否正在使用,使用驱动程序查询数据库 jdbc,因此如果连接有效,则发送错误消息以更改端口。
所以这是我以前做的方法,但我不知道如何在 Inno Setup 中做:
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection(
"jdbc:mysql://" + server + ":" + port + "/database", "root", password);
if (conn.isValid(0)) {
error = "A server-type installation already exists in: " + server;
return Status.ERROR;
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
}
非常感谢。
您将必须执行命令行 MySQL 客户端 (mysql
)。
有关执行可执行文件和检查其退出代码 and/or 检查其输出的一些示例,请参阅:
- Using Process Exit code to show error message for a specific File in [Run];
- How to get an output of an Exec'ed program in Inno Setup?
找到了一种从答案中发现端口的简单方法 How to check if port is usable in Inno Setup?
function CheckPortOccupied(Port:String):Boolean;
var
ResultCode: Integer;
begin
Exec(ExpandConstant('{cmd}'), '/C netstat -na | findstr'+' /C:":'+Port+' "', '', 0,
ewWaitUntilTerminated, ResultCode);
if ResultCode <> 1 then
begin
Log('this port('+Port+') is occupied');
Result := True;
end
else
begin
Result := False;
end;
end;