private void extractDataInCsv() {
try {
File file = new File(this.getClass().getResource("/com/ibm/commerce/data/OrdersDataExtract.sql").toURI());
Runtime rt = Runtime.getRuntime();
String executeSqlCommand= null;
if(getRequestProperties().getBoolean("localDev",false)){
executeSqlCommand = "db2cmd /c /i /w && db2 -tvf "+file.getAbsolutePath(); // local dev windows
}else{
executeSqlCommand = "db2 -vf "+file.getAbsolutePath(); // linux
}
Process pr = rt.exec(executeSqlCommand);
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
//pause for 15se
Thread.sleep(15000);
} catch (Exception e) {
e.printStackTrace();
}
}
Script in OrdersDataExtract.sql is as follows:
connect to dbname user dbusername using password
set schema db2inst1
-- extract data
EXPORT TO /opt/IBM/WebSphere/AppServer/temp/OrdersDataExtract.csv OF DEL MODIFIED BY NOCHARDEL striplzeros decplusblank select with ur
terminate
No comments:
Post a Comment