1

Before knowing about Inno Setup used IzPack to do my installer, due to the need to verify if the port of the service that was about to create was in use, towards a query to the database with the driver jdbc, so if the connection was valid then send a error message to change the port.

So this is the way I did before, but I do not know how to do it in 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);
}

Thank you very much.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • Do you install MySQL on your own? Or do you rely on existing MySQL installation? + Your code does not show any query, nor what you do with results. – Martin Prikryl May 30 '17 at 08:09
  • sorry i think that was call a query, my friend told me, but now i kno its a conection, just want to try to replicate the code, but I found an easy way that discover the used port, and thank you so much for you responses. – Angel Montes de Oca May 30 '17 at 14:41
  • Post it as an answer. – Martin Prikryl May 30 '17 at 14:44
  • OK, now after you edited your question, my answer does not make sense. And your question is duplicate of https://stackoverflow.com/q/21701847/850848 (as you found yourself) + Though the MySQL query question is useful. So if you do not mind, I'm reverting your question for benefit of others. – Martin Prikryl May 30 '17 at 15:19
  • thats good thank you – Angel Montes de Oca May 30 '17 at 15:28

2 Answers2

2

You will have to execute a command-line MySQL client (mysql).

For some examples of executing an executable and checking its exit code and/or inspecting its output, see:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

found an easy way to discover port from answer 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;