public String getProfiles( String mKey ) {
		
		StringBuffer sb = new StringBuffer();
		sb.append("select id,key,title,description,reverse_cost,");
		sb.append("public,enabled,pgr_sp,pgr_dd,rid from app.profiles ");
		
		if( mKey != null ) {
			sb.append("where key in (").append(mKey).append(") ");			
		}
		
		sb.append("order by id");
		
		String sql  = sb.toString();
		String rval = new String();

		JSONObject jo     = new JSONObject();
		JSONArray  data   = new JSONArray();
		JSONObject status = new JSONObject();
		
		try {
			DBConn dbConn = new DBConn();
			Connection conn = dbConn.getConnection();
			Statement stmt  = conn.createStatement();
			ResultSet rs    = stmt.executeQuery(sql);
			
			while( rs.next() ) {
				JSONObject rec = new JSONObject();
				JSONObject profile = new JSONObject();
				JSONArray  config  = new JSONArray();
				JSONArray  hosts   = new JSONArray();
				
				profile.put("id"          , rs.getInt("id"));
				profile.put("rid"         , rs.getInt("rid"));
				profile.put("key"         , rs.getString("key"));
				profile.put("title"       , rs.getString("title"));
				profile.put("description" , rs.getString("description"));
				profile.put("reverse_cost", rs.getBoolean("reverse_cost"));
				profile.put("public"      , rs.getBoolean("public"));
				profile.put("enabled"     , rs.getBoolean("enabled"));
				profile.put("pgr_sp"      , rs.getBoolean("pgr_sp"));
				profile.put("pgr_dd"      , rs.getBoolean("pgr_dd"));
				
				sql = "select cid,speed,enabled,priority "+
				    "from app.configuration "+
					"where pid="+ rs.getInt("id"); 
				Statement stmt2 = conn.createStatement();
				ResultSet rs2   = stmt2.executeQuery(sql);
				
				while(rs2.next()) {
					JSONObject c = new JSONObject();
					c.put("cid",     rs2.getInt("cid"));
					c.put("speed",   rs2.getInt("speed"));
					c.put("enabled", rs2.getBoolean("enabled"));
					c.put("priority",rs2.getDouble("priority"));
					
					config.add(c);
				}
				
				sql = "select host from app.hosts where id="+rs.getInt("id");
				Statement stmt3 = conn.createStatement();
				ResultSet rs3   = stmt3.executeQuery(sql);
				
				while( rs3.next() ) {
					hosts.add(rs3.getString("host"));
				}
								
				rec.put("hosts", hosts);
				rec.put("configuration", config);
				rec.put("profile", profile);
				
				data.add(rec);
				
				rs2.close();
				rs3.close();
				stmt2.close();
				stmt3.close();
			}
			
			status.put("code"   , new Integer(201));
			status.put("success", true);
			status.put("message","completed successfully");
			
			jo.put("data"  , data);
			jo.put("status", status);
			
			rval = jo.toString();
			
			rs.close();
			stmt.close();
			conn.close();
		}
		catch( Exception ex ) {
			ex.printStackTrace();
			
			try {
				status.put("code"   , new Integer(404));
				status.put("success", false);
				status.put("message","database access error");
				
				jo.put("data"  , data);
				jo.put("status", status);
				
				rval = jo.toString();
			}
			catch( Exception exception ) {;}
		}
		
		return rval;
	}