Exécution d'une procedure stocké depuis java
Exécution d'une procedure stocké depuis java
CallableStatement call = null;
String sql = "{call MySchema.MyProcName}";
call = con.prepareCall(sql);
call.execute();
call.close();
**************************************************
Execution d'un programme externe depuis java : http://ydisanto.developpez.com/tutoriels/j2se/runtime/
private void cmdsLaunch(String extractCmd, String assemblyCmd,
String cmdsFileNamePath_p)throws IOException {
StringBuffer commandsFile = getEnvVariables();
commandsFile.append(extractCmd);
commandsFile.append(System.getProperty("line.separator"));
commandsFile.append(assemblyCmd);
try {
writeFile(cmdsFileNamePath_p, commandsFile.toString());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
String[] cmdArray = { "cmd.exe", "/c", cmdsFileNamePath_p };
// Commande SQL.
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(cmdArray);
// Utilisation d'un thread pour lire ce que contient le buffer.
StreamReader streamReader = new StreamReader(process.getInputStream());
streamReader.run();
int status =0;
try {
status = process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
// Output.
System.out.println(streamReader.getContents()+"\r\n") ;
System.out.println("Status execution =" +status) ;
if (status!=0) {
throw new RuntimeException("Error :- Execution de commande Echouée");
}
}