return res;
}
//SELECT QUERY
public static Result executeQuery(String querySQL) {
Result res = new Result();
String row="";
try {
Connect();
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(querySQL);
//the table names
if(rs.next()) {
row="";
int cols = rs.getMetaData().getColumnCount();
for(int i=1;i<cols;i++)
row+= (rs.getMetaData().getColumnName(i) + ",");
row+=rs.getMetaData().getColumnName(cols);
// row+=rs.getString(cols);
res.addResult(row);
}
//the actual data
rs = stat.executeQuery(querySQL);
while (rs.next()) {
row="";
int numCols = rs.getMetaData().getColumnCount();
//join row content
for (int i=1; i < numCols; i++) {
row+= (rs.getString(i) + ",");
}
row+=rs.getString(numCols);
res.addResult(row);
}
String txtquery="======> " + querySQL +" :: run successfully";
writeToLog( txtquery);
stat.close();
Disconnect();
res.setResMessage(ResultMessage.OK);
} catch (Exception ex) {
Logger.getLogger(DataBase.class.getName()).log(Level.WARNING, null, ex);
res.addResult(ex.getMessage());
res.setResMessage(ResultMessage.DB_EX);
String txtquery="======> " + querySQL +"\n"+" ERROR: query discarded by the data base - "+ ex.getMessage();
writeToLog( txtquery);
}
return res;