public CachedRowSet getData(String tableName, List<ColumnDetail> cols, List<ColumnDetail> orderByCols) throws MainException {
		try{
			Statement stmt = null;
			ResultSet results = null;
			CachedRowSet crs = new CachedRowSetImpl();
			
			List<String> tables = new ArrayList<String>();
			//Print select clause
			String query = "SELECT DISTINCT ";
			Iterator<ColumnDetail> colsItr = cols.iterator();
			while(colsItr.hasNext()){
				ColumnDetail col = colsItr.next();
				String colTable = col.getTableName();
				if(!tables.contains(colTable)){
					tables.add(colTable);
				}
				String colName = col.getName();
				query += colTable +"." + colName;
				if(colsItr.hasNext()) query+=", ";
			}
			query += " FROM ";
			Iterator<String> tablesItr = tables.iterator();
			while(tablesItr.hasNext()){
				String tName = tablesItr.next();
				query += tName;
				if(tablesItr.hasNext()) query+=", ";
			}
			
			boolean isFirst = true;
			if(tables.size()>1){
				query += " WHERE ";
				
				List<String> pks = this.getPrimaryKeys(tableName);
				for(int i=0; i<pks.size(); i++){
					String pkCol = pks.get(i);
					for(int j=0; j<tables.size(); j++){
						String tName = tables.get(j);
						if(!tName.equals(tableName)){
							if(isFirst){
								query += tableName +"."+pkCol+"="+tName+"."+pkCol;
							}else{
								query += ", "+ tableName +"."+pkCol+"="+tName+"."+pkCol;
							}
						}
					}
				}
			}
			query += " ORDER BY ";
			int n = orderByCols.size();
			for(int i=0; i<n; i++){
				ColumnDetail col = orderByCols.get(i);
				String tName = col.getTableName();
				String colName = col.getName();
				query += tName +"."+colName;
				if(i<n-1){
					query+=", ";
				}

			}
			query += ";";
			logger.info("Get data query: " +query);
			stmt = dbConnection.createStatement();
			results = stmt.executeQuery(query);
			crs.populate(results);
			stmt.close();
			return crs;
			//return results;
		}catch(SQLException ex){
			ex.printStackTrace();
			throw new MainException("Exception when retrieving data from table " + tableName + " : " + ex.getMessage());

		}catch(Exception ex){
			ex.printStackTrace();
			throw new MainException("Exception at DBAccess.getData(tableName) when retrieving data from table " + tableName);
		}
	}