package es.uv.saic.service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import es.uv.saic.domain.IndicadorEnquesta;

//Este servicio no hay que adaptarlo
@Service
public class ParserService {
	
	@Autowired
	private IndicadorEnquestaService ies;
	@Autowired 
	private SysStatusService sss;
	@Value("${saic.parser.surveys.path}")
	private String surveysPath;
	@Value("${saic.uqserver.host}")
	private String host;
	@Value("${saic.uqserver.user}")
	private String user;
	@Value("${saic.uqserver.passwd}")
	private String passwd;
	@Value("${saic.uqserver.dbname.grau}")
	private String dbnameGrau;
	@Value("${saic.uqserver.dbname.master}")
	private String dbnameMaster;
	@Value("${saic.uqserver.dbname.prof}")
	private String dbnameProf;
	@Value("${saic.uqserver2.host}")
	private String host2;
	@Value("${saic.uqserver2.user}")
	private String user2;
	@Value("${saic.uqserver2.passwd}")
	private String passwd2;
	@Value("${saic.uqserver2.dbname.master}")
	private String dbnameMaster2;
	@Value("${saic.uqserver2.dbname.prof}")
	private String dbnameProf2;
	@Value("${saic.uqserver2.dbname.otros}")
	private String dbnameOtros2;
	@Value("${saic.uqserver2.dbname.doct}")
	private String dbnameDoctorado2;
	@Value("${saic.data.master}")
	private String pathFilesMaster;
	@Value("${saic.data.doctorado}")
	private String pathFilesDoctorado;
	@Value("${saic.data.evdocente}")
	private String pathFilesEvdocente;
	
	
	private HashMap<String, String> titsMap;
	
	public ParserService() {
		titsMap = new HashMap<String, String>();
		titsMap.put("TRAD", "1099");
	}
	
	public String doParse(String database, String table, String year) throws ClassNotFoundException {
		int r = 0;
		switch(database) {
			case "grado":
				r += this.parseGrauFromUqServer(table, year);
				break;
			case "master":
				r += this.parseMasterFromUqServer(table, year);
				break;
			case "evalprof":
				r += this.parseEvalProf(table, year);
				break;
			case "otros":
				r += this.parseOtros(table);
				break;
			case "pas":
				r += this.parsePas(table, year);
				break;
			case "doctorado":
				r += this.parseDoctorado(table, year);
				break;
			case "todos":
				r += this.parseGrauFromUqServer(table, year);
				r += this.parseMasterFromUqServer(table, year);
				r += this.parseEvalProf(table, year);
				r += this.parseDoctorado(table, year);
				r += this.parseOtros(table);
				break;
			default: 
				break;
		}
		return Integer.toString(r);
	}
		
	public int parseOtros(String table) throws ClassNotFoundException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameOtros2+"?user="+this.user2+"&password="+this.passwd2;
		int r = 0;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			switch(table) {
				case "otros":
					r += this.parseOtrosProfes(connection);
					r += this.parseOtrosTasas(connection);
					break;
				case "enquestes":	
					r += this.parseOtrosEncuestas(connection);
					break;
				case "docentia":
					r += this.parseOtrosDocentia(connection);
					break;
				case "todos":
					r += this.parseOtrosProfes(connection);
					r += this.parseOtrosTasas(connection);
					r += this.parseOtrosDocentia(connection);
					break;
				default:
					break;
			}
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
        }
		return r;
	}
	
	public int parsePas(String table, String year) throws ClassNotFoundException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host+"/"+this.dbnameGrau+"?user="+this.user+"&password="+this.passwd+"&serverTimezone=GMT";
		int r = 0;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			r += this.parseDadesPas(connection, year);
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
        }
		return r;
	}
	
	public int parseEvalProf(String table, String year) throws ClassNotFoundException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameProf2+"?user="+this.user2+"&password="+this.passwd2;
		int r = 0;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			r += this.parseEvalProfBD(connection, year);
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
        }
		return r;
	}
	
	public int parseGrauFromUqServer(String table, String year) throws ClassNotFoundException {	
		
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host+"/"+this.dbnameGrau+"?user="+this.user+"&password="+this.passwd+"&serverTimezone=GMT";
		int r = 0;
		try (Connection connection = DriverManager.getConnection(connUrl)) {	
			switch(table) {
				case "dades1er":
					r += this.parseGrauDades1er(connection, year);
					break;
				case "dades3er":
					r += this.parseGrauDades3er(connection, year);
					break;
				case "dadesGraduats":
					r += this.parseGrauDadesGraduats(connection, year);
					break;
				case "profes":
					r += this.parseGrauProfes(connection, year);
					break;
				case "todos":
					r += this.parseGrauDades1er(connection, year);
					r += this.parseGrauDades3er(connection, year);
					r += this.parseGrauDadesGraduats(connection, year);
					r += this.parseGrauProfes(connection, year);
					break;
				default:
					break;
			}
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
        }
		return r;
	}
	
	public int parseMasterFromUqServer(String table, String year) throws ClassNotFoundException {	
		
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameMaster2+"?user="+this.user2+"&password="+this.passwd2;
		int r = 0;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			
			switch(table) {
				case "data":
					r += this.parseMasterData(connection, year);
					break;
				case "datag":
					r += this.parseMasterDataG(connection, year);
					break;
				case "profes":
					r += this.parseMasterProfes(connection, year);
					break;
				case "todos":
					r += this.parseMasterData(connection, year);
					r += this.parseMasterDataG(connection, year);
					r += this.parseMasterProfes(connection, year);
					break;
				default:
					break;
			}
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
        }
		return r;
	}
	
	public int parseDoctorado(String table, String year) throws ClassNotFoundException {	
		
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameDoctorado2+"?user="+this.user2+"&password="+this.passwd2;
		int r = 0;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			
			switch(table) {
				case "estud":
					r += this.parseDocEstud(connection, year);
					break;
				case "etesi":
					r += this.parseDocEtesi(connection, year);
					break;
				case "prof":
					r += this.parseDocProf(connection, year);
					break;
				case "inds":
					r += this.parseDocInds(connection, year);
					break;
				case "tasas":
					r += this.parseDocTasas(connection, year);
					break;
				case "recom":
					r += this.parseDocRecom(connection, year);
					break;
				case "todos":
					r += this.parseDocEstud(connection, year);
					r += this.parseDocEtesi(connection, year);
					r += this.parseDocProf(connection, year);
					r += this.parseDocInds(connection, year);
					r += this.parseDocTasas(connection, year);
					r += this.parseDocRecom(connection, year);
					break;
				default:
					break;
			}
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
        }
		return r;
	}
		
	private int execute(Statement statement, String[] queries) throws SQLException {
		int r = 1;
		for(String sql : queries) {
			
			System.out.println(sql);
			
	        ResultSet result = statement.executeQuery(sql);
	        ResultSetMetaData resultMetadata = result.getMetaData();
	        int columns = resultMetadata.getColumnCount();
	   
	        while (result.next()) {
	        	String c = result.getString("centre");
	        	String t = result.getString("tit");
	        	String ambit = result.getString("ambit");
	        	Integer titulacio = null;
	        	Integer centre = null;
	        		        	
	        	boolean isvalid = false;
	        	if(ambit.equals("T") && c != null && t != null) {
	        		t = translate(t);
	        		if(StringUtils.isNumeric(t) && StringUtils.isNumeric(c.replace("C", ""))) {
	        			titulacio = Integer.parseInt(t);
	        			centre = Integer.parseInt(c.replace("C", ""));
	        			isvalid = true;
	        		}
	        	}
	        	else if(ambit.equals("C") && c != null && t == null) {
	        		if(StringUtils.isNumeric(c.replace("C", ""))) {
	        			centre = Integer.parseInt(c.replace("C", ""));
	        			isvalid = true;
	        		}
	        	}
	        	else if(ambit.equals("U")) {
	        		isvalid = true;
	        	}
	        		        	
	        	if(isvalid) {
	        		String enquesta = result.getString("enquesta");		        	
		        	Integer curs = result.getInt("curs");
		        	for(int i = 8; i <= columns; i++) {
		        		IndicadorEnquesta ie = new IndicadorEnquesta();
		            	ie.setEnquesta(enquesta);
		        		ie.setTitulacio(titulacio);
		        		ie.setCentre(centre);
		        		ie.setCurs(curs);
		        		ie.setAmbit(ambit); 
		            	ie.setIndicador(resultMetadata.getColumnLabel(i).replace("_min", "").replace("_max", "").toLowerCase());
		            	ie.setNum(null);
		            	ie.setEstudi(result.getString("estudi").toLowerCase());
		            	ie.setCursd(result.getString("cursd"));
		            	String tipus = "avg";
		            	if(resultMetadata.getColumnLabel(i).endsWith("_min")) {
		            		tipus = "min";
		            	}
		            	else if(resultMetadata.getColumnLabel(i).endsWith("_max")) {
		            		tipus = "max";
		            	}
		            	ie.setTipus(tipus);
		            	try {
		            		ie.setValor(result.getString(i).replace(",", "."));
		            	}
		            	catch(Exception ex) {
		            		ie.setValor(null);
		            	}
		            	
		            	ies.save(ie);
		            	r+=1;
		        	}   
	        	}
	        }
		}
		return r;
	}
	
	private int executeRows(Statement statement, String[] queries) throws SQLException {
		int r = 1;
		for(String sql : queries) {
			
			System.out.println(sql);
			
	        ResultSet result = statement.executeQuery(sql);
	   
	        while (result.next()) {
	        	String c = result.getString("centre");
	        	String t = result.getString("tit");
	        	String ambit = result.getString("ambit");
	        	Integer titulacio = null;
	        	Integer centre = null;
	        		        	
	        	boolean isvalid = false;
	        	if(ambit.equals("T") && c != null && t != null) {
	        		t = translate(t);
	        		if(StringUtils.isNumeric(t) && StringUtils.isNumeric(c.replace("C", ""))) {
	        			titulacio = Integer.parseInt(t);
	        			centre = Integer.parseInt(c.replace("C", ""));
	        			isvalid = true;
	        		}
	        	}
	        	else if(ambit.equals("C") && c != null && t == null) {
	        		if(StringUtils.isNumeric(c.replace("C", ""))) {
	        			centre = Integer.parseInt(c.replace("C", ""));
	        			isvalid = true;
	        		}
	        	}
	        	else if(ambit.equals("U")) {
	        		isvalid = true;
	        	}
	        		        	
	        	if(isvalid) {
		        	IndicadorEnquesta ie = new IndicadorEnquesta();
	            	ie.setEnquesta(result.getString("enquesta"));
	        		ie.setTitulacio(titulacio);
	        		ie.setCentre(centre);
	        		ie.setCurs(result.getInt("curs"));
	        		ie.setAmbit(ambit); 
	            	ie.setIndicador(result.getString("indicador").replace("_min", "").replace("_max", "").toLowerCase());
	            	ie.setNum(result.getString("num"));
	            	ie.setEstudi(result.getString("estudi").toLowerCase());
	            	ie.setCursd(result.getString("cursd"));
	            	String tipus = "avg";
	            	if(result.getString("indicador").endsWith("_min")) {
	            		tipus = "min";
	            	}
	            	else if(result.getString("indicador").endsWith("_max")) {
	            		tipus = "max";
	            	}
	            	ie.setTipus(tipus);
	            	try {
	            		ie.setValor(result.getString("valor"));
	            	}
	            	catch(Exception ex) {
	            		ie.setValor(null);
	            	}
	            	
	            	ies.save(ie);
	            	r+=1;  
	        	}
	        }
		}
		return r;
	}
	
	private String translate(String t) {
		if(StringUtils.isNumeric(t)) {
			return t;
		}
		
		String r = this.titsMap.get(t);
		return r == null ? t : r;
	}
	
	private int parseGrauDades1er(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'dades_1er' AS enquesta, tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'g' AS estudi, "
				+ "(i01/N_enquestes)*100 AS i01, i02m AS i02, i03m AS i03, i03v2m AS i03v2, i04m AS i04, i05m AS i05, i06m AS i06, i07m AS i07, "
				+ "i08m AS i08, i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, i14m AS i14, i15m AS i15, "
				+ "i16m AS i16, i17m AS i17, i18m AS i18, i19m AS i19, i20m AS i20, i21m AS i21, (i22_si/(i22_si+i22_no))*100 AS i22, "
				+ "i24m AS i24, i24_titm AS i24_tit, i24_mercatm AS i24_mercat, (i25_si/(i25_si+i25_no))*100 AS i25, "
				+ "(i26_si/(i26_si+i26_no))*100 AS i26, igual1m AS igual1 "
				+ "FROM MDB_grau.recomptes_1erA a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+" AND N_enquestes >= 3;",
		
				"SELECT 'dades_1er' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "(i01/N_enquestes)*100 AS i01, i02m AS i02, i03m AS i03, i03v2m AS i03v2, i04m AS i04, i05m AS i05, i06m AS i06, "
				+ "i07m AS i07, i08m AS i08, i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, "
				+ "i14m AS i14, i15m AS i15, i16m AS i16, i17m AS i17, i18m AS i18, i19m AS i19, i20m AS i20, "
				+ "i21m AS i21, (i22_si/(i22_si+i22_no))*100 AS i22, i24m AS i24, i24_titm AS i24_tit, "
				+ "i24_mercatm AS i24_mercat, (i25_si/(i25_si+i25_no))*100 AS i25, (i26_si/(i26_si+i26_no))*100 AS i26, igual1m AS igual1 "
				+ "FROM MDB_grau.recomptes_1er_curscentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+" AND N_enquestes >= 3;",
				
				"SELECT 'dades_1er' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "bibliom AS biblio, cafem AS cafe, reprom AS repro "
				+ "FROM MDB_grau.recomptes_1er_curscentre_bibcaf a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
		
				"SELECT 'dades_1er' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'g' AS estudi, "
				+ "(i01/N_enquestes)*100 AS i01, i02m AS i02, i03m AS i03, i03v2m AS i03v2, i04m AS i04, i05m AS i05, i06m AS i06, "
				+ "i07m AS i07, i08m AS i08, i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, "
				+ "i14m AS i14, i15m AS i15, i16m AS i16, i17m AS i17, i18m AS i18, i19m AS i19, i20m AS i20, "
				+ "i21m AS i21, (i22_si/(i22_si+i22_no))*100 AS i22, i24m AS i24, i24_titm AS i24_tit, "
				+ "i24_mercatm AS i24_mercat, (i25_si/(i25_si+i25_no))*100 AS i25, (i26_si/(i26_si+i26_no))*100 AS i26, igual1m AS igual1 "
				+ "FROM MDB_grau.global WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+" AND N_enquestes >= 3;",
				
				"SELECT 'dades_1er' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'g' AS estudi, "
				+ "bibliom AS biblio, cafem AS cafe, reprom AS repro "
				+ "FROM MDB_grau.global_1er_bibcaf WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
				
				"SELECT 'dades_1er' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "max_pi01*100 AS i01_max, min_pi01*100 AS i01_min, max_i02m AS i02_max, min_i02m AS i02_min, "
				+ "max_i03v2m AS i03v2_max, min_i03v2m AS i03v2_min, max_i07m AS i07_max, min_i07m AS i07_min, "
				+ "max_i08m AS i08_max, min_i08m AS i08_min, "
				+ "max_i16m AS i16_max, min_i16m AS i16_min, max_i17m AS i17_max, min_i17m AS i17_min, "
				+ "max_pi22*100 AS i22_max, min_pi22*100 AS i22_min, max_pi25*100 AS i25_max, "
				+ "min_pi25*100 AS i25_min, max_pi26*100 AS i26_max, min_pi26*100 AS i26_min "
				+ "FROM MDB_grau.MinMax_1er_curscentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseGrauDades3er(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'dades_3er' AS enquesta, tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'g' AS estudi, "
				+ "(i01/N_enquestes)*100 AS i01, i02m AS i02, i03m AS i03, i04m AS i04, i05m AS i05, i06m AS i06, i07m AS i07, "
				+ "i08m AS i08, i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, i14m AS i14, i15m AS i15, "
				+ "i16m AS i16, i17m AS i17, i18m AS i18, i19m AS i19, i20m AS i20, i21m AS i21, i22m AS i22, "
				+ "i24m AS i24, i25_titm AS i24_tit, i25_mercatm AS i24_mercat, i26m AS i26, igual1m AS igual1  "
				+ "FROM MDB_grau.recomptes_3erA a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+" AND N_enquestes >= 3;",
				
				"SELECT 'dades_3er' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "(i01/N_enquestes)*100 AS i01, i02m AS i02, i03m AS i03, i04m AS i04, i05m AS i05, i06m AS i06, "
				+ "i07m AS i07, i08m AS i08, i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, "
				+ "i14m AS i14, i15m AS i15, i16m AS i16, i17m AS i17, i18m AS i18, i19m AS i19, i20m AS i20, "
				+ "i21m AS i21, i22m AS i22, i24m AS i24, i25_titm AS i24_tit, i25_mercatm AS i24_mercat, "
				+ "i26m AS i26, igual1m AS igual1  "
				+ "FROM MDB_grau.recomptes_3er_curscentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+" AND N_enquestes >= 3;",
				
				"SELECT 'dades_3er' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "bibliom AS biblio, cafem AS cafe, reprom AS repro "
				+ "FROM MDB_grau.recomptes_3er_curscentre_bibcaf a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
				
				"SELECT 'dades_3er' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'g' AS estudi, "
				+ "(i01/N_enquestes)*100 AS i01, i02m AS i02, i03m AS i03, i04m AS i04, i05m AS i05, i06m AS i06, "
				+ "i07m AS i07, i08m AS i08, i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, "
				+ "i14m AS i14, i15m AS i15, i16m AS i16, i17m AS i17, i18m AS i18, i19m AS i19, i20m AS i20, "
				+ "i21m AS i21, i22m AS i22, i24m AS i24, i25_titm AS i24_tit, i25_mercatm AS i24_mercat, "
				+ "i26m AS i26, igual1m AS igual1  "
				+ "FROM MDB_grau.global_3er WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+" AND N_enquestes >= 3",
				
				"SELECT 'dades_3er' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'g' AS estudi, "
				+ "bibliom AS biblio, cafem AS cafe, reprom AS repro "
				+ "FROM MDB_grau.global_3er_bibcaf WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
				
				"SELECT 'dades_3er' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "max_pi01*100 AS i01_max, min_pi01*100 AS i01_min, max_i02m AS i02_max, min_i02m AS i02_min, "
				+ "max_i08m AS i08_max, min_i08m AS i08_min, max_i02m AS i09_max, min_i09m AS i09_min, "
				+ "max_i18m AS i18_max, min_i18m AS i18_min, max_i20m AS i20_max, min_i20m AS i20_min "
				+ "FROM MDB_grau.MinMax_3er_curscentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseGrauDadesGraduats(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'dades_graduats' AS enquesta, tit, cmostrar AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'T' AS ambit, 'g' AS estudi, "
				+ "it01m_pf AS it01_pf, it02m_pf AS it02_pf, it03m_pf AS it03_pf, it04m_comp AS it04_comp, it05m_comp AS it05_comp, "
				+ "it06m_comp AS it06_comp, it07m_comp AS it07_comp, it08m_comp AS it08_comp, it09m_comp AS it09_comp, "
				+ "it10m_de AS it10_de, it11m_de AS it11_de, it12m_de AS it12_de, it13m_de AS it13_de, it14m_de AS it14_de, "
				+ "it15m_de AS it15_de, it17m_pe AS it17_pe, it18m_pe AS it18_pe, it19m_pe AS it19_pe, it20m_pe AS it20_pe, "
				+ "it21m_pe AS it21_pe, it22m_pe AS it22_pe, it25m_mob AS it25_mob, it26m_mob AS it26_mob, it27m_mob AS it27_mob, "
				+ "it28m_mob AS it28_mob, it29m_mob AS it29_mob, it30m_mob AS it30_mob, it31m_mob AS it31_mob, it32m_mob AS it32_mob, "
				+ "it33m_tfg AS it33_tfg, it34m_tfg AS it34_tfg, it35m_tfg AS it35_tfg, it36m_tfg AS it36_tfg, it37m_tfg AS it37_tfg, "
				+ "it39m_treb AS it39_treb, it40m_treb AS it40_treb, it41m_treb AS it41_treb, it42m_treb AS it42_treb, "
				+ "gm_Qprof AS g_Qprof, gm_instal AS g_instal, gm_exp AS g_exp, gm_recomana AS g_recomana "
				+ "FROM MDB_grau.GMitjanes_xtitcursfA a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+" AND total >= 3;",
				
				"SELECT 'dades_graduats' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "it01m_pf AS it01_pf, it02m_pf AS it02_pf, it03m_pf AS it03_pf, it04m_comp AS it04_comp, it05m_comp AS it05_comp, "
				+ "it06m_comp AS it06_comp, it07m_comp AS it07_comp, it08m_comp AS it08_comp, it09m_comp AS it09_comp, "
				+ "it10m_de AS it10_de, it11m_de AS it11_de, it12m_de AS it12_de, it13m_de AS it13_de, it14m_de AS it14_de, "
				+ "it15m_de AS it15_de, it17m_pe AS it17_pe, it18m_pe AS it18_pe, it19m_pe AS it19_pe, it20m_pe AS it20_pe, "
				+ "it21m_pe AS it21_pe, it22m_pe AS it22_pe, it25m_mob AS it25_mob, it26m_mob AS it26_mob, it27m_mob AS it27_mob, "
				+ "it28m_mob AS it28_mob, it29m_mob AS it29_mob, it30m_mob AS it30_mob, it31m_mob AS it31_mob, it32m_mob AS it32_mob, "
				+ "it33m_tfg AS it33_tfg, it34m_tfg AS it34_tfg, it35m_tfg AS it35_tfg, it36m_tfg AS it36_tfg, it37m_tfg AS it37_tfg, "
				+ "it39m_treb AS it39_treb, it40m_treb AS it40_treb, it41m_treb AS it41_treb, it42m_treb AS it42_treb, "
				+ "gm_Qprof AS g_Qprof, gm_instal AS g_instal, gm_exp AS g_exp, gm_recomana AS g_recomana "
				+ "FROM MDB_grau.GMitjanes_xcentrecursf a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+" AND total >= 3;",
				
				"SELECT 'dades_graduats' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'U' AS ambit, 'g' AS estudi, "
				+ "it01m_pf AS it01_pf, it02m_pf AS it02_pf, it03m_pf AS it03_pf, it04m_comp AS it04_comp, it05m_comp AS it05_comp, "
				+ "it06m_comp AS it06_comp, it07m_comp AS it07_comp, it08m_comp AS it08_comp, it09m_comp AS it09_comp, "
				+ "it10m_de AS it10_de, it11m_de AS it11_de, it12m_de AS it12_de, it13m_de AS it13_de, it14m_de AS it14_de, "
				+ "it15m_de AS it15_de, it17m_pe AS it17_pe, it18m_pe AS it18_pe, it19m_pe AS it19_pe, it20m_pe AS it20_pe, "
				+ "it21m_pe AS it21_pe, it22m_pe AS it22_pe, it25m_mob AS it25_mob, it26m_mob AS it26_mob, it27m_mob AS it27_mob, "
				+ "it28m_mob AS it28_mob, it29m_mob AS it29_mob, it30m_mob AS it30_mob, it31m_mob AS it31_mob, it32m_mob AS it32_mob, "
				+ "it33m_tfg AS it33_tfg, it34m_tfg AS it34_tfg, it35m_tfg AS it35_tfg, it36m_tfg AS it36_tfg, it37m_tfg AS it37_tfg, "
				+ "it39m_treb AS it39_treb, it40m_treb AS it40_treb, it41m_treb AS it41_treb, it42m_treb AS it42_treb, "
				+ "gm_Qprof AS g_Qprof, gm_instal AS g_instal, gm_exp AS g_exp, gm_recomana AS g_recomana "
				+ "FROM MDB_grau.GMitjanes_xcursf WHERE pertany = 1 AND CONCAT('20', RIGHT(cursf, 2)) >= "+year+" AND total >= 3;",
				
				"SELECT 'dades_graduats' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "max_it13m_de AS it13_de_max, min_it13m_de AS it13_de_min, max_it14m_de AS it14_de_max, min_it14m_de AS it14_de_min, "
				+ "max_it15m_de AS it15_de_max, min_it15m_de AS it15_de_min, max_it17m_pe AS it17_pe_max, min_it17m_pe AS it17_pe_min, "
				+ "max_it18m_pe AS it18_pe_max, min_it18m_pe AS it18_pe_min, max_it19m_pe AS it19_pe_max, min_it19m_pe AS it19_pe_min, "
				+ "max_it20m_pe AS it20_pe_max, min_it20m_pe AS it20_pe_min, max_it21m_pe AS it21_pe_max, min_it21m_pe AS it21_pe_min,"
				+ "max_it22m_pe AS it22_pe_max, min_it22m_pe AS it22_pe_min, max_it25m_mob AS it25_mob_max, min_it25m_mob AS it25_mob_min, "
				+ "max_it26m_mob AS it26_mob_max, min_it26m_mob AS it26_mob_min, max_it27m_mob AS it27_mob_max, min_it27m_mob AS it27_mob_min,"
				+ "max_it28m_mob AS it28_mob_max, min_it28m_mob AS it28_mob_min, max_it29m_mob AS it29_mob_max, min_it29m_mob AS it29_mob_min, "
				+ "max_it30m_mob AS it30_mob_max, min_it30m_mob AS it30_mob_min, max_it310m_mob AS it31_mob_max, min_it31m_mob AS it31_mob_min, "
				+ "max_it32m_mob AS it32_mob_max, min_it32m_mob AS it32_mob_min, "
				+ "max_gm_instal AS g_instal_max, min_gm_instal AS g_instal_min "
				+ "FROM MDB_grau.MinMax_grad_cursfcentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseGrauProfes(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'profes' AS enquesta, tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'g' AS estudi, "
				+ "a2m AS a2, a3m AS a3, a4m AS a4, a6m AS a6, a7m AS a7, a9m AS a9, a11m AS a11, a13m AS a13, a14m AS a14, "
				+ "a15_1m AS a15_1, a15_2m AS a15_2, a15_3m AS a15_3, a15_4m AS a15_4, a16m AS a16, a17m AS a17, a19m AS a19, "
				+ "a20m AS a20, a21m AS a21, a27m AS a27, a28m AS a28, a29m AS a29, a31m AS a31, a32m AS a32 "
				+ "FROM MDB_grau.recomptes_profesA a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
				
				"SELECT 'profes' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "a2m AS a2, a3m AS a3, a4m AS a4, a6m AS a6, a7m AS a7, a9m AS a9, a11m AS a11, "
				+ "a13m AS a13, a14m AS a14, a15_1m AS a15_1, a15_2m AS a15_2, a15_3m AS a15_3, "
				+ "a15_4m AS a15_4, a16m AS a16, a17m AS a17, a19m AS a19, a20m AS a20, a21m AS a21, "
				+ "a27m AS a27, a28m AS a28, a29m AS a29, a31m AS a31, a32m AS a32 "
				+ "FROM MDB_grau.recomptes_profes_curscentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
				
				"SELECT 'profes' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'g' AS estudi, "
				+ "a2m AS a2, a3m AS a3, a4m AS a4, a6m AS a6, a7m AS a7, a9m AS a9, a11m AS a11, "
				+ "a13m AS a13, a14m AS a14, a15_1m AS a15_1, a15_2m AS a15_2, a15_3m AS a15_3, "
				+ "a15_4m AS a15_4, a16m AS a16, a17m AS a17, a19m AS a19, a20m AS a20, a21m AS a21, "
				+ "a27m AS a27, a28m AS a28, a29m AS a29, a31m AS a31, a32m AS a32 "
				+ "FROM MDB_grau.global_profes WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+"",
				
				"SELECT 'profes' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'g' AS estudi, "
				+ "max_A9m AS a9_max, min_A9m AS a9_min, max_A11m AS a11_max, min_A11m AS a11_min, "
				+ "max_A13m AS a13_max, min_A13m AS a13_min, max_A16m AS a16_max, min_A16m AS a16_min,"
				+ "max_A17m AS a17_max, min_A17m AS a17_min, max_A19m AS a19_max, min_A19m AS a19_min,"
				+ "max_A28m AS a28_max, min_A28m AS a28_min "
				+ "FROM MDB_grau.MinMax_profes_curscentre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseDadesPas(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'dadespas' AS enquesta, NULL AS tit, cmostrar AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'C' AS ambit, 'u' AS estudi, "
				+ "i01m AS i01, i02m AS i02, i03m AS i03, i04m AS i04, i05m AS i05, i06m AS i06, i07m AS i07, i08m AS i08, "
				+ "i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, i14m AS i14, i15m AS i15, i16m AS i16, "
				+ "g1m AS g1, g2m AS g2, g3m AS g3, g4m AS g4 "
				+ "FROM MDB_grau.recomptesPAS_centre a "
				+ "LEFT JOIN MDB_grau.Centre b ON a.centre = b.centre "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";",
				
				"SELECT 'dadespas' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(curs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'u' AS estudi,"
				+ "i01m AS i01, i02m AS i02, i03m AS i03, i04m AS i04, i05m AS i05, i06m AS i06, i07m AS i07, i08m AS i08, "
				+ "i09m AS i09, i10m AS i10, i11m AS i11, i12m AS i12, i13m AS i13, i14m AS i14, i15m AS i15, i16m AS i16, "
				+ "g1m AS g1, g2m AS g2, g3m AS g3, g4m AS g4 "
				+ "FROM MDB_grau.global_PAS a "
				+ "WHERE CONCAT('20', RIGHT(curs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseMasterData(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'data' AS enquesta, b.tit AS tit, c.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'T' AS ambit, 'm' AS estudi, "
				+ "IT01 AS it01, IT02 AS it02, IT03 AS it03, IT04 AS it04, IT05 AS it05, IT06 AS it06, "
				+ "IT07 AS it07, IT08 AS it08, IT09 AS it09, IT10 AS it10, IT11 AS it11, IT12 AS it12, "
				+ "IT13 AS it13, IT14 AS it14, IT15 AS it15, IT16 AS it16, IT17 AS it17, IT18 AS it18, "
				+ "IT19 AS it19, IT21 AS it21, IT22 AS it22, IT23 AS it23, IT24 AS it24, IT25 AS it25, "
				+ "IT26 AS it26, IT27 AS it27, IT28 AS it28, IT29 AS it29, IT30 AS it30, IT30 AS it30, "
				+ "IT31 AS it31, IT32 AS it32, IT33 AS it33, G_satis AS g_satis, G_RelQP AS g_relqp, "
				+ "G_QProf AS g_qprof, G_Postg AS g_postg, G_Interes AS g_interes, G_Util AS g_util "
				+ "FROM MDB_master.Mitjanes_final a "
				+ "LEFT JOIN MDB_master.ESTUDIS b ON a.tit = b.tit "
				+ "LEFT JOIN MDB_master.Centre c ON b.centre = c.centre "
				+ "WHERE CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",
				
				/*+ "AND a.TIT NOT IN(SELECT DISTINCT(TIT) FROM MDB_master.Mitjanes_final_codigeneric) "
				+ "UNION "
				+ "SELECT 'data' AS enquesta, b.tit AS tit, c.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'T' AS ambit, 'm' AS estudi, "
				+ "IT01 AS it01, IT02 AS it02, IT03 AS it03, IT04 AS it04, IT05 AS it05, IT06 AS it06, "
				+ "IT07 AS it07, IT08 AS it08, IT09 AS it09, IT10 AS it10, IT11 AS it11, IT12 AS it12, "
				+ "IT13 AS it13, IT14 AS it14, IT15 AS it15, IT16 AS it16, IT17 AS it17, IT18 AS it18, "
				+ "IT19 AS it19, IT21 AS it21, IT22 AS it22, IT23 AS it23, IT24 AS it24, IT25 AS it25, "
				+ "IT26 AS it26, IT27 AS it27, IT28 AS it28, IT29 AS it29, IT30 AS it30, IT30 AS it30, "
				+ "IT31 AS it31, IT32 AS it32, IT33 AS it33, G_satis AS g_satis, G_RelQP AS g_relqp, "
				+ "G_QProf AS g_qprof, G_Postg AS g_postg, G_Interes AS g_interes, G_Util AS g_util, gcovidm AS gcovid "
				+ "FROM MDB_master.Mitjanes_final_codigeneric a "
				+ "LEFT JOIN MDB_master.ESTUDIS b ON a.tit = b.tit "
				+ "LEFT JOIN MDB_master.Centre c ON b.centre = c.centre "
				+ "WHERE Total >= 3 AND CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",*/
				
				"SELECT 'data' AS enquesta, NULL AS tit, b.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'C' AS ambit, 'm' AS estudi, "
				+ "IT01 AS it01, IT02 AS it02, IT03 AS it03, IT04 AS it04, IT05 AS it05, IT06 AS it06, "
				+ "IT07 AS it07, IT08 AS it08, IT09 AS it09, IT10 AS it10, IT11 AS it11, IT12 AS it12, IT13 AS it13, "
				+ "IT14 AS it14, IT15 AS it15, IT16 AS it16, IT17 AS it17, IT18 AS it18, IT19 AS it19, "
				+ "IT21 AS it21, IT22 AS it22, IT23 AS it23, IT24 AS it24, IT25 AS it25, IT26 AS it26, "
				+ "IT27 AS it27, IT28 AS it28, IT29 AS it29, IT30 AS it30, IT30 AS it30, IT31 AS it31, "
				+ "IT32 AS it32, IT33 AS it33, G_satis AS g_satis, G_RelQP AS g_relqp, G_QProf AS g_qprof, "
				+ "G_Postg AS g_postg, G_Interes AS g_interes, G_Util AS g_util "
				+ "FROM MDB_master.Mitjanes_final_xcentre a "
				+ "LEFT JOIN MDB_master.Centre b ON a.centre = b.centre WHERE CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",
				
				"SELECT 'data' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'U' AS ambit, 'm' AS estudi, "
				+ "IT01 AS it01, IT02 AS it02, IT03 AS it03, IT04 AS it04, IT05 AS it05, IT06 AS it06, "
				+ "IT07 AS it07, IT08 AS it08, IT09 AS it09, IT10 AS it10, IT11 AS it11, IT12 AS it12, IT13 AS it13, "
				+ "IT14 AS it14, IT15 AS it15, IT16 AS it16, IT17 AS it17, IT18 AS it18, IT19 AS it19, "
				+ "IT21 AS it21, IT22 AS it22, IT23 AS it23, IT24 AS it24, IT25 AS it25, IT26 AS it26, "
				+ "IT27 AS it27, IT28 AS it28, IT29 AS it29, IT30 AS it30, IT30 AS it30, IT31 AS it31, "
				+ "IT32 AS it32, IT33 AS it33, G_satis AS g_satis, G_RelQP AS g_relqp, G_QProf AS g_qprof, "
				+ "G_Postg AS g_postg, G_Interes AS g_interes, G_Util AS g_util "
				+ "FROM MDB_master.Mitjanes_final_global "
				+ "WHERE CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",
				
				"SELECT 'data' AS enquesta, NULL AS tit, b.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'C' AS ambit, 'm' AS estudi, "
				+ "max_it13m AS it13_max, min_it13m AS it13_min, max_it14m AS it14_max, min_it14m AS it14_min, "
				+ "max_it15m AS it15_max, min_it15m AS it15_min, max_it16m AS it16_max, min_it16m AS it16_min, "
				+ "max_it17m AS it17_max, min_it17m AS it17_min "
				+ "FROM MDB_master.MinMax_final_xcentre a "
				+ "LEFT JOIN MDB_master.Centre b ON a.centre = b.centre WHERE CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseMasterDataG(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'data_g' AS enquesta, b.tit AS tit, c.cmostrar AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'T' AS ambit, 'm' AS estudi, "
				+ "IT01m_pf AS it01_pf, IT02m_pf AS it02_pf, IT03m_pf AS it03_pf, IT04m_comp AS it04_comp, "
				+ "IT04m_comp AS it05_comp, IT06m_comp AS it06_comp, IT07m_comp AS it07_comp, "
				+ "IT08m_comp AS it08_comp, IT09m_comp AS it09_comp, IT10m_comp AS it10_comp, "
				+ "IT11m_de AS it11_de, IT12m_de AS it12_de, IT13m_de AS it13_de, IT14m_de AS it14_de, "
				+ "IT15m_de AS it15_de, IT16m_de AS it16_de, (IT17_pe_S/(IT17_pe_S+IT17_pe_N))*100 AS it17_pe, "
				+ "IT18m_pe AS it18_pe, IT19m_pe AS it19_pe, IT20m_pe AS it20_pe, IT21m_pe AS it21_pe, "
				+ "IT22m_pe AS it22_pe, IT23m_pe AS it23_pe, (IT24_mob_S/(IT24_mob_S+IT24_mob_N))*100 AS it24_mob, "
				+ "IT25_mob1 AS it25_mob1, IT25_mob2 AS it25_mob2, IT25_mob3 AS it25_mob3, IT25_mob4 AS it25_mob4, "
				+ "IT26m_mob AS it26_mob, IT27m_mob AS it27_mob, IT28m_mob AS it28_mob, IT29m_mob AS it29_mob, "
				+ "IT30m_mob AS it30_mob, IT26m_mob AS it26_mob, IT31m_mob AS it31_mob, IT32m_mob AS it32_mob, "
				+ "IT33m_mob AS it33_mob, IT34m_tfm AS it34_tfm, IT35m_tfm AS it35_tfm, IT36m_tfm AS it36_tfm, "
				+ "IT37m_tfm AS it37_tfm, IT38m_tfm AS it38_tfm, IT40m_treb AS it40_treb, IT41m_treb AS it41_treb, "
				+ "IT41m_treb AS it41_treb, IT42m_treb AS it42_treb, IT43m_treb AS it43_treb, gm_Qprof AS g_qprof, "
				+ "gm_instal AS g_instal, gm_exp AS g_exp, gm_recomana AS g_recomana "
				+ "FROM MDB_master.Mitjanes_Gxtitcursf a "
				+ "LEFT JOIN MDB_master.ESTUDIS b ON a.tit = b.tit "
				+ "LEFT JOIN MDB_master.Centre c ON b.centre = c.centre WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+";",
				
				"SELECT 'data_g' AS enquesta, NULL AS tit, b.cmostrar AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'C' AS ambit, 'm' AS estudi, "
				+ "IT01m_pf AS it01_pf, IT02m_pf AS it02_pf, IT03m_pf AS it03_pf, IT04m_comp AS it04_comp, "
				+ "IT04m_comp AS it05_comp, IT06m_comp AS it06_comp, IT07m_comp AS it07_comp, "
				+ "IT08m_comp AS it08_comp, IT09m_comp AS it09_comp, IT10m_comp AS it10_comp, "
				+ "IT11m_de AS it11_de, IT12m_de AS it12_de, IT13m_de AS it13_de, IT14m_de AS it14_de, "
				+ "IT15m_de AS it15_de, IT16m_de AS it16_de, (IT17_pe_S/(IT17_pe_S+IT17_pe_N))*100 AS it17_pe, "
				+ "IT18m_pe AS it18_pe, IT19m_pe AS it19_pe, IT20m_pe AS it20_pe, IT21m_pe AS it21_pe, "
				+ "IT22m_pe AS it22_pe, IT23m_pe AS it23_pe, (IT24_mob_S/(IT24_mob_S+IT24_mob_N))*100 AS it24_mob, "
				+ "IT25_mob1 AS it25_mob1, IT25_mob2 AS it25_mob2, IT25_mob3 AS it25_mob3, IT25_mob4 AS it25_mob4, "
				+ "IT26m_mob AS it26_mob, IT27m_mob AS it27_mob, IT28m_mob AS it28_mob, IT29m_mob AS it29_mob, "
				+ "IT30m_mob AS it30_mob, IT26m_mob AS it26_mob, IT31m_mob AS it31_mob, IT32m_mob AS it32_mob, "
				+ "IT33m_mob AS it33_mob, IT34m_tfm AS it34_tfm, IT35m_tfm AS it35_tfm, IT36m_tfm AS it36_tfm, "
				+ "IT37m_tfm AS it37_tfm, IT38m_tfm AS it38_tfm, IT40m_treb AS it40_treb, IT41m_treb AS it41_treb, "
				+ "IT41m_treb AS it41_treb, IT42m_treb AS it42_treb, IT43m_treb AS it43_treb, gm_Qprof AS g_qprof, "
				+ "gm_instal AS g_instal, gm_exp AS g_exp, gm_recomana AS g_recomana "
				+ "FROM MDB_master.Mitjanes_Gxcentrecursf a "
				+ "LEFT JOIN MDB_master.Centre b ON a.centre = b.centre WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+";",
				
				"SELECT 'data_g' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'U' AS ambit, 'm' AS estudi, "
				+ "IT01m_pf AS it01_pf, IT02m_pf AS it02_pf, IT03m_pf AS it03_pf, IT04m_comp AS it04_comp, "
				+ "IT04m_comp AS it05_comp, IT06m_comp AS it06_comp, IT07m_comp AS it07_comp, "
				+ "IT08m_comp AS it08_comp, IT09m_comp AS it09_comp, IT10m_comp AS it10_comp, "
				+ "IT11m_de AS it11_de, IT12m_de AS it12_de, IT13m_de AS it13_de, IT14m_de AS it14_de, "
				+ "IT15m_de AS it15_de, IT16m_de AS it16_de, (IT17_pe_S/(IT17_pe_S+IT17_pe_N))*100 AS it17_pe, "
				+ "IT18m_pe AS it18_pe, IT19m_pe AS it19_pe, IT20m_pe AS it20_pe, IT21m_pe AS it21_pe, "
				+ "IT22m_pe AS it22_pe, IT23m_pe AS it23_pe, (IT24_mob_S/(IT24_mob_S+IT24_mob_N))*100 AS it24_mob, "
				+ "IT25_mob1 AS it25_mob1, IT25_mob2 AS it25_mob2, IT25_mob3 AS it25_mob3, IT25_mob4 AS it25_mob4, "
				+ "IT26m_mob AS it26_mob, IT27m_mob AS it27_mob, IT28m_mob AS it28_mob, IT29m_mob AS it29_mob, "
				+ "IT30m_mob AS it30_mob, IT26m_mob AS it26_mob, IT31m_mob AS it31_mob, IT32m_mob AS it32_mob, "
				+ "IT33m_mob AS it33_mob, IT34m_tfm AS it34_tfm, IT35m_tfm AS it35_tfm, IT36m_tfm AS it36_tfm, "
				+ "IT37m_tfm AS it37_tfm, IT38m_tfm AS it38_tfm, IT40m_treb AS it40_treb, IT41m_treb AS it41_treb, "
				+ "IT41m_treb AS it41_treb, IT42m_treb AS it42_treb, IT43m_treb AS it43_treb, gm_Qprof AS g_qprof, "
				+ "gm_instal AS g_instal, gm_exp AS g_exp, gm_recomana AS g_recomana "
				+ "FROM MDB_master.Mitjanes_Gxcursf WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+";",
				
				"SELECT 'data_g' AS enquesta, NULL AS tit, b.cmostrar AS centre, CONCAT('20', RIGHT(cursf, 2)) AS curs, null AS cursd, 'C' AS ambit, 'm' AS estudi, "
				+ "max_IT26m_mob AS it26_mob_max, min_IT26m_mob AS it26_mob_min, "
				+ "max_IT27m_mob AS it27_mob_max, min_IT27m_mob AS it27_mob_min, "
				+ "max_IT28m_mob AS it28_mob_max, min_IT28m_mob AS it28_mob_min, "
				+ "max_IT29m_mob AS it29_mob_max, min_IT29m_mob AS it29_mob_min, "
				+ "max_IT30m_mob AS it30_mob_max, min_IT30m_mob AS it30_mob_min, "
				+ "max_IT31m_mob AS it31_mob_max, min_IT31m_mob AS it31_mob_min, "
				+ "max_IT32m_mob AS it32_mob_max, min_IT32m_mob AS it32_mob_min, "
				+ "max_IT33m_mob AS it33_mob_max, min_IT33m_mob AS it33_mob_min, "
				+ "max_gm_instal AS g_instal_max, min_gm_instal AS g_instal_min "
				+ "FROM MDB_master.MinMax_Gxcursfcentre a "
				+ "LEFT JOIN MDB_master.Centre b ON a.centre = b.centre WHERE CONCAT('20', RIGHT(cursf, 2)) >= "+year+";"
				};
		
		return this.execute(statement, queries);
	}
	
	private int parseMasterProfes(Connection connection, String year) throws SQLException {	
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'profes_tancades' AS enquesta, b.tit AS tit, c.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'T' AS ambit, 'm' AS estudi, "
				+ "A1 AS a1, A2 AS a2, A3 AS a3, A4 AS a4, A5 AS a5, A6 AS a6, A7 AS a7, A8 AS a8, A9 AS a9, A10 AS a10, "
				+ "A11 AS a11, A12 as a12, A13 AS a13, A14 AS a14, A15_1 AS a15_1, A15_2 AS a15_2, A15_3 AS a15_3, "
				+ "A15_4 AS a15_4, A15_5 AS a15_5, A16 AS a16, A17 AS a17, A18 AS a18, A19 AS a19, A20 AS a20, "
				+ "A21 AS a21, A26 AS a26, A27 AS a27, A28 AS a28, A29 AS a29, A30 AS a30, A31 AS a31, A32 AS a32 "
				+ "FROM MDB_master.Mitjanes_profesXtit a "
				+ "LEFT JOIN MDB_master.ESTUDIS b ON a.tit = b.tit "
				+ "LEFT JOIN MDB_master.Centre c ON b.centre = c.centre WHERE CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",
				
				"SELECT 'profes_tancades' AS enquesta, NULL AS tit, c.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'C' AS ambit, 'm' AS estudi, "
				+ "A1 AS a1, A2 AS a2, A3 AS a3, A4 AS a4, A5 AS a5, A6 AS a6, A7 AS a7, A8 AS a8, A9 AS a9, A10 AS a10, "
				+ "A11 AS a11, A12 as a12, A13 AS a13, A14 AS a14, A15_1 AS a15_1, A15_2 AS a15_2, A15_3 AS a15_3, "
				+ "A15_4 AS a15_4, A15_5 AS a15_5, A16 AS a16, A17 AS a17, A18 AS a18, A19 AS a19, A20 AS a20, "
				+ "A21 AS a21, A26 AS a26, A27 AS a27, A28 AS a28, A29 AS a29, A30 AS a30, A31 AS a31, A32 AS a32 "
				+ "FROM MDB_master.Mitjanes_profesxCurscentre a "
				+ "LEFT JOIN MDB_master.periodesCurs p ON p.curs = CONCAT('20', RIGHT(ACURS, 2)) "
				+ "LEFT JOIN MDB_master.Centre c ON a.centre = c.centre WHERE p.ProfesComplet = 1 AND CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",
				
				"SELECT 'profes_tancades' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'U' AS ambit, 'm' AS estudi,"
				+ "A1 AS a1, A2 AS a2, A3 AS a3, A4 AS a4, A5 AS a5, A6 AS a6, A7 AS a7, A8 AS a8, A9 AS a9, A10 AS a10, "
				+ "A11 AS a11, A12 as a12, A13 AS a13, A14 AS a14, A15_1 AS a15_1, A15_2 AS a15_2, A15_3 AS a15_3, "
				+ "A15_4 AS a15_4, A15_5 AS a15_5, A16 AS a16, A17 AS a17, A18 AS a18, A19 AS a19, A20 AS a20, "
				+ "A21 AS a21, A26 AS a26, A27 AS a27, A28 AS a28, A29 AS a29, A30 AS a30, A31 AS a31, A32 AS a32 "
				+ "FROM MDB_master.Mitjanes_profesxCurs a"
				+ "LEFT JOIN MDB_master.periodesCurs p ON p.curs = CONCAT('20', RIGHT(ACURS, 2)) "
				+ "WHERE p.ProfesComplet = 1 AND CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";",
				
				"SELECT 'profes_tancades' AS enquesta, NULL AS tit, c.cmostrar AS centre, CONCAT('20', RIGHT(ACURS, 2)) AS curs, null AS cursd, 'C' AS ambit, 'm' AS estudi, "
				+ "max_A16m AS a16_max, min_A16m AS a16_min, max_A17m AS a17_max, min_A17m AS a17_min, "
				+ "max_A19m AS a19_max, min_A19m AS a19_min "
				+ "FROM MDB_master.MinMax_profesxCurscentre a "
				+ "LEFT JOIN MDB_master.periodesCurs p ON p.curs = CONCAT('20', RIGHT(ACURS, 2)) "
				+ "LEFT JOIN MDB_master.Centre c ON a.centre = c.centre WHERE p.ProfesComplet = 1 AND CONCAT('20', RIGHT(ACURS, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	
	private int parseEvalProfBD(Connection connection, String year) throws SQLException {	
		 
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'evalprof' AS enquesta, t.cod_titula AS tit, c.cod_actual AS centre, CONCAT('20', anyo) AS curs, null AS cursd, 'T' AS ambit, tipus AS estudi, "
				+ "it01, it02, it03, it04, it05, it06, it07, it08, it09, it10, it11, it12, it13, it14, b1, b2, b3, b4, b5, b6, global "
				+ "FROM MDB_evalProf.MediasTitulacion m "
				+ "LEFT JOIN MDB_evalProf.Titulaciones t ON m.estudio = t.estudio "
				+ "LEFT JOIN MDB_evalProf.Centros c ON t.cod_centro = c.cod_centro "
				+ "WHERE c.cod_actual IS NOT NULL AND c.cod_actual <> '' AND num_encues >= 3 AND CONCAT('20', anyo) >= "+year+"; ",
				
				"SELECT 'evalprof' AS enquesta, NULL AS tit, c.cod_actual AS centre, CONCAT('20', anyo) AS curs, null AS cursd, 'C' AS ambit, tipus AS estudi, "
				+ "it01, it02, it03, it04, it05, it06, it07, it08, it09, it10, it11, it12, it13, it14, b1, b2, b3, b4, b5, b6, global "
				+ "FROM MDB_evalProf.MediasCentro m "
				+ "LEFT JOIN MDB_evalProf.Centros c ON m.centre = c.cod_centro "
				+ "LEFT JOIN MDB_master.periodesCurs p ON p.curs = CONCAT('20', anyo) "
				+ "WHERE c.cod_actual IS NOT NULL AND c.cod_actual <> '' AND CONCAT('20', anyo) >= "+year+"; ",
				
				"SELECT 'evalprof' AS enquesta, NULL AS tit, NULL AS centre, CONCAT('20', anyo) AS curs, null AS cursd, 'U' AS ambit, tipus AS estudi, "
				+ "it01, it02, it03, it04, it05, it06, it07, it08, it09, it10, it11, it12, it13, it14, b1, b2, b3, b4, b5, b6, global "
				+ "FROM MDB_evalProf.MediasUniversidad "
				+ "LEFT JOIN MDB_master.periodesCurs p ON p.curs = CONCAT('20', anyo) "
				+ "WHERE CONCAT('20', anyo) >= "+year+"; "};
		
		return this.execute(statement, queries);
		
	}
	
	private int parseOtrosProfes(Connection connection) throws SQLException {	
		 
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'otros' AS enquesta, t.cod_titula AS tit, c.cod_actual AS centre, curs, null AS cursd, ambit, estudi, "
				+ "I_RH2_06, I_RH2_07, I_RH2_08, I_RH2_profcursos, I_RH2_totpdi "
				+ "FROM MDB_otros.profesorado m "
				+ "LEFT JOIN MDB_evalProf.Titulaciones t ON m.titulacion = t.estudio "
				+ "LEFT JOIN MDB_evalProf.Centros c ON t.cod_centro = c.cod_centro "
				+ "WHERE c.cod_actual IS NOT NULL AND c.cod_actual <> '';"};
		
		return this.execute(statement, queries);
		
	}
	
	private int parseOtrosEncuestas(Connection connection) throws SQLException {	
		 
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'enquestes' AS enquesta, titulacio AS tit, centre, curs, null AS cursd, ambit, estudi, "
				+ "1er_modul_cod, 1er_modul_nom, 1er_modul_obs, 3er_modul_cod, 3er_modul_nom, 3er_modul_obs "
				+ "FROM MDB_otros.asignaturas_encuestas;"};
		
		return this.execute(statement, queries);
		
	}
	
	private int parseOtrosTasas(Connection connection) throws SQLException {	
		 
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'otros' AS enquesta, t.cod_titula AS tit, c.cod_actual AS centre, curs, null AS cursd, ambit, estudi, "
				+ "i_oe1_nb_nuevos, i_oe1_nb_plazas, i_oe1_tasa_mat, i_oe1_tasa_ofedem "
				+ "FROM MDB_otros.tasas m "
				+ "LEFT JOIN MDB_evalProf.Titulaciones t ON m.titulacion = t.estudio "
				+ "LEFT JOIN MDB_evalProf.Centros c ON t.cod_centro = c.cod_centro "
				+ "WHERE c.cod_actual IS NOT NULL AND c.cod_actual <> '';"};
		
		return this.execute(statement, queries);
		
	}
	
	private int parseOtrosDocentia(Connection connection) throws SQLException {	
		 
		Statement statement = connection.createStatement();
		String[] queries = {				
				"SELECT *  "
				+ "FROM MDB_otros.docentia_evaluacion "
				+ "WHERE centre IS NOT NULL;"};
		
		return this.execute(statement, queries);
		
	}
	
	/* ToDo */
	private int parseDocEstud(Connection connection, String year) throws SQLException {
		// escuela doctorado = 62
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'doc_estud' AS enquesta, pro.prg_mostrar AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "i01m, i02m, i03m, i04m, i05m, i06m, i07m, i08m, i09m, i10m, i11m, i12m, i13m, i14m, i16m, i17m, i18m, i19m, i20m, i21m, i22m, i23m, "
				+ "i03d1m, i04d1m, i05d1m, i05d2m, i06d1m, i06d2m, i06d3m, i06d4m, i07d1m, i08d1m, i08d2m, i09d1m, i09d2m, i24m, i25m, i26m, i27m, i28m, "
				+ "i29m, i30m, i31m, i32m, i33m, i34m, i35m, g_Qprofm, g_instalm, g_activm, g_expm, g_recomanam "
				+ "FROM MDB_doctorado.recom_estud_xprg1 LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_estud' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i01m, i02m, i03m, i04m, i05m, i06m, i07m, i08m, i09m, i10m, i11m, i12m, i13m, i14m, i16m, i17m, i18m, i19m, i20m, i21m, i22m, i23m "
				+ "FROM MDB_doctorado.recom_estud_xcurs1 "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_estud' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i24m, i25m, i26m, i27m, i28m, i29m, i30m, i31m, i32m, i33m, i34m, i35m, g_Qprofm, g_instalm, g_activm, g_expm, g_recomanam "
				+ "FROM MDB_doctorado.recom_estud_xcurs2 "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",

				"SELECT 'doc_estud' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i03d1m, i04d1m, i05d1m, i05d2m, i06d1m, i06d2m, i06d3m, i06d4m, i07d1m, i08d1m, i08d2m, i09d1m, i09d2m "
				+ "FROM MDB_doctorado.recom_estud_xcurs6 "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_estud' AS enquesta, prg AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "indicador_estud_programa AS ind_prg, ind_estud_pdi AS ind_pdi "
				+ "FROM MDB_doctorado.Indicador_estud_v2022 LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_estud' AS enquesta, prg AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "b_instal "
				+ "FROM MDB_doctorado.recom_estud_xprg4_bloc LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enqg >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseDocEtesi(Connection connection, String year) throws SQLException {
		// escuela doctorado = 62
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'doc_etesi' AS enquesta, pro.prg_mostrar AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "i01m, i02m, i03m, i04m, i05m, i06m, i07m, i08m, i09m, i10m, i11m, i12m, i13m, i14m, i16m, i17m, i18m, i19m, i20m, i21m, i22m, i23m, i24m, "
				+ "i25m, i26m, i27m, i28m, i29m, i30m "
				+ "FROM MDB_doctorado.recom_etesi_xprg1_SAIC LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_etesi' AS enquesta, pro.prg_mostrar AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "i31m, i32m, i33m, i34m, i35m, i37m, g_Qprofm, g_instalm, g_activ1m, g_activ2m, g_expm, g_recomanam "
				+ "FROM MDB_doctorado.recom_etesi_xprg2 LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_etesi' AS enquesta, pro.prg_mostrar AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "i03d1m, i04d1m, i05d1m, i05d2m, i06d1m, i06d2m, i06d3m, i06d4m, i07d1m, i08d1m, i08d2m, i09d1m, i09d2m "
				+ "FROM MDB_doctorado.recom_etesi_xprg5 LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_etesi' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i01m, i02m, i03m, i04m, i05m, i06m, i07m, i08m, i09m, i10m, i11m, i12m, i13m, i14m, i16m, i17m, i18m, i19m, i20m, i21m, i22m, i23m, i24m, "
				+ "i25m, i26m, i27m, i28m, i29m, i30m "
				+ "FROM MDB_doctorado.recom_etesi_xcurs1_SAIC WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_etesi' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i31m, i32m, i33m, i34m, i35m, i37m, g_Qprofm, g_instalm, g_activ1m, g_activ2m, g_expm, g_recomanam "
				+ "FROM MDB_doctorado.recom_etesi_xcurs2 WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_etesi' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i03d1m, i04d1m, i05d1m, i05d2m, i06d1m, i06d2m, i06d3m, i06d4m, i07d1m, i08d1m, i08d2m, i09d1m, i09d2m "
				+ "FROM MDB_doctorado.recom_etesi_xcurs5 WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_etesi' AS enquesta, prg AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "indicador_egressat_programa AS ind_prg, ind_egre_pdi AS ind_pdi, ind_egre_director AS ind_director "
				+ "FROM MDB_doctorado.Indicador_etesi_v2022 LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseDocProf(Connection connection, String year) throws SQLException {
		// escuela doctorado = 62
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'doc_prof' AS enquesta, pro.prg_mostrar AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "i01m, i02m, i03m, i04m, i05m, i06m, i07m, i08m, i09m, i10m, i11m, i12m, i13m, i14m, i15m, i16m, i17m, i18m, i19m, i20m, i21m, b_alum "
				+ "FROM MDB_doctorado.recom_prof_xprg1 LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_prof' AS enquesta, NULL AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'U' AS ambit, 'd' AS estudi, "
				+ "i01m, i02m, i03m, i04m, i05m, i06m, i07m, i08m, i09m, i10m, i11m, i12m, i13m, i14m, i15m, i16m, i17m, i18m, i19m, i20m, i21m, b_alum "
				+ "FROM MDB_doctorado.recom_prof_xcurs1 WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";",
				
				"SELECT 'doc_prof' AS enquesta, prg AS tit, 62 AS centre, CONCAT('20', RIGHT(acurs, 2)) AS curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "indicador_prof AS ind_prof "
				+ "FROM MDB_doctorado.Indicador_prof LEFT JOIN MDB_doctorado.Programa pro ON prg = pro.prg_uv "
				+ "WHERE N_enq >= 3 AND CONCAT('20', RIGHT(acurs, 2)) >= "+year+";"};
		
		return this.execute(statement, queries);
	}
	
	private int parseDocTasas(Connection connection, String year) throws SQLException {
			
			Statement statement = connection.createStatement();
			String[] queries = {
					"SELECT 'doc_tasas' AS enquesta, titulacion AS tit, 62 AS centre, curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
					+ "n_prof_dire, n_prof, d_i01, n_prof_sex, n_prof_noaso, d_i02, n_prof_proy, d_i03, n_prof_ip, d_i04, n_tesis_ext, n_tesis, d_i05 "
					+ "FROM MDB_doctorado.tasas WHERE curs >= "+year+";"};
			
			return this.execute(statement, queries);
	}
	
	private int parseDocInds(Connection connection, String year) throws SQLException {
		
		Statement statement = connection.createStatement();
		String[] queries = {
				"SELECT 'doc_inds' AS enquesta, titulacion AS tit, 62 AS centre, curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, "
				+ "I_OED_01, I_OED_02, I_OED_03, I_OED_04, I_OED_05, I_OED_07, I_OED_08, I_DED_01, I_DED_02, I_DED_03, I_DED_04,"
				+ "I_DED_05, I_DED_06 "
				+ "FROM MDB_doctorado.indicadores WHERE curs >= "+year+"; "};
		
		return this.execute(statement, queries);
}
	
	private int parseDocRecom(Connection connection, String year) throws SQLException {
		Statement statement = connection.createStatement();
		String[] queries = {
			"SELECT LOWER(enquesta) AS enquesta, indicador, SUBSTRING_INDEX(indicador, '_', 1) AS num, tit, 62 AS centre, "
			+ "curs, null AS cursd, 'T' AS ambit, 'd' AS estudi, valor "
			+ "FROM MDB_doctorado.doc_recom WHERE curs >= "+year+";"};
		
		return this.executeRows(statement, queries);
	}
	
	public String doAction(String action) throws ClassNotFoundException {
		
		String r = "0";
		try {
			switch(action) {
				case "mediasCentroNP":
					r = Integer.toString(this.ies.deleteCentroNoAdscrito());
					break;
				case "bienalesProfesGrado":
					r = Integer.toString(this.ies.fixBiennials("profes", 2022));
					break;
				case "bienalesProfesMaster":
					r = Integer.toString(this.ies.fixBiennials("profes_tancades", 2022));
					break;
				case "bienalesPas":
					r = Integer.toString(this.ies.fixBiennials("dadespas", 2022));
					break;
				case "precargaEvalprof":
					r = this.precargaEvalProf();
					break;
				case "precargaMaster": 
					r = this.precargaMaster();
					break;
				case "precargaDoctorado":
					r = this.precargaDoctorado();
					break;
				default:
					break;
			}
		}
		catch (SQLException ex){
			return "-1";
		}
		
		return r;
		
	}
	
	public String precargaEvalProf() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameProf2+"?user="+this.user2+"&password="+this.passwd2+"&allowLoadLocalInfile=true";
		
		String queries[] = {"DELETE FROM MDB_evalProf.MediasUniversidad; ",
				            "DELETE FROM MDB_evalProf.MediasCentro; ",
				            "DELETE FROM MDB_evalProf.MediasTitulacion; ",
				            "LOAD DATA LOCAL INFILE '"+pathFilesEvdocente+"tit.txt' INTO TABLE MDB_evalProf.MediasTitulacion "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
				            "LOAD DATA LOCAL INFILE '"+pathFilesEvdocente+"centre.txt' INTO TABLE MDB_evalProf.MediasCentro "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
				            "UPDATE MDB_evalProf.Titulaciones SET cod_centro = '111' WHERE cod_titula = '2153'; ",
				            "UPDATE MDB_evalProf.Titulaciones SET cod_centro = '121' WHERE cod_titula = '2208'; ",
				            "INSERT INTO MDB_evalProf.MediasUniversidad "
				            		+ "SELECT * FROM MDB_evalProf.MediasTitulacion WHERE estudio = 'GRAU' OR estudio = 'MAST';",
				            "DELETE FROM MDB_evalProf.MediasTitulacion WHERE estudio = 'GRAU' OR estudio = 'MAST' OR estudio = 'TRAD';",
				            "UPDATE MDB_evalProf.MediasTitulacion SET tipus = 'G' WHERE CAST(estudio AS UNSIGNED) < 2000;",
				            "UPDATE MDB_evalProf.MediasTitulacion SET tipus = 'M' WHERE CAST(estudio AS UNSIGNED) >= 2000 AND CAST(estudio AS UNSIGNED) < 3000;",
				            "UPDATE MDB_evalProf.MediasUniversidad SET tipus = 'G' WHERE estudio = 'GRAU';",
				            "UPDATE MDB_evalProf.MediasUniversidad SET tipus = 'M' WHERE estudio = 'MAST';",
				            "UPDATE MDB_evalProf.MediasCentro SET tipus = 'G' WHERE tipus = 'GRAU';",
				            "UPDATE MDB_evalProf.MediasCentro SET tipus = 'M' WHERE tipus LIKE 'M_STER';"
				            };
		
		Statement statement = null;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			statement = connection.createStatement();
			for(String q : queries) { statement.addBatch(q); }
			statement.executeBatch();
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
            return "-1";
		}
		finally {
			if(statement != null) { statement.close(); }
		}
		
		return "1";
	}
	
	
	public String precargaMaster() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameMaster2+"?user="+this.user2+"&password="+this.passwd2+"&allowLoadLocalInfile=true";
		
		String queries[] = {"DELETE FROM MDB_master.Mitjanes_profesXtit; ",
				            "DELETE FROM MDB_master.Mitjanes_profesxCurscentre; ",
				            "DELETE FROM MDB_master.Mitjanes_profesxCurs; ",
				            "DELETE FROM MDB_master.Mitjanes_Gxtitcursf; ",
				            "DELETE FROM MDB_master.Mitjanes_Gxcursf; ",
				            "DELETE FROM MDB_master.Mitjanes_Gxcentrecursf; ",
				            "DELETE FROM MDB_master.Mitjanes_final_xcentre; ",
				            "DELETE FROM MDB_master.MinMax_final_xcentre; ",
				            "DELETE FROM MDB_master.MinMax_profesxCurscentre; ",
				            "DELETE FROM MDB_master.MinMax_Gxcursfcentre; ",
				            "DELETE FROM MDB_master.Mitjanes_final_global; ",
				            //"DELETE FROM MDB_master.Mitjanes_final_codigeneric; ",
				            "DELETE FROM MDB_master.Mitjanes_final; ",
				            "LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_profesXtit.csv' INTO TABLE MDB_master.Mitjanes_profesXtit "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
				            "LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_profesxCurscentre.csv' INTO TABLE MDB_master.Mitjanes_profesxCurscentre "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_profesxCurs.csv' INTO TABLE MDB_master.Mitjanes_profesxCurs "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_Gxtitcursf.csv' INTO TABLE MDB_master.Mitjanes_Gxtitcursf "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_Gxcursf.csv' INTO TABLE MDB_master.Mitjanes_Gxcursf "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_Gxcentrecursf.csv' INTO TABLE MDB_master.Mitjanes_Gxcentrecursf "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_final_xcentre.csv' INTO TABLE MDB_master.Mitjanes_final_xcentre "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"MinMax_final_xcentre.csv' INTO TABLE MDB_master.MinMax_final_xcentre "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"MinMax_profesxCurscentre.csv' INTO TABLE MDB_master.MinMax_profesxCurscentre "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",         		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"MinMax_Gxcursfcentre.csv' INTO TABLE MDB_master.MinMax_Gxcursfcentre "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",   		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_final_global.csv' INTO TABLE MDB_master.Mitjanes_final_global "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		//"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_final_codigeneric.csv' INTO TABLE MDB_master.Mitjanes_final_codigeneric "
				            //		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",         		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesMaster+"Mitjanes_final.csv' INTO TABLE MDB_master.Mitjanes_final "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; "	
				            };
		
		Statement statement = null;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			statement = connection.createStatement();
			for(String q : queries) { statement.addBatch(q); }
			statement.executeBatch();
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
            return "-1";
		}
		finally {
			if(statement != null) { statement.close(); }
		}
		
		return "1";
	}
	
	public String precargaDoctorado() throws ClassNotFoundException, SQLException {
		Class.forName("com.mysql.cj.jdbc.Driver");
		String connUrl = "jdbc:mysql://"+this.host2+"/"+this.dbnameDoctorado2+"?user="+this.user2+"&password="+this.passwd2+"&allowLoadLocalInfile=true";
		
		String queries[] = {"DELETE FROM MDB_doctorado.recom_etesi_xprg1; ",
							"DELETE FROM MDB_doctorado.recom_etesi_xprg1_SAIC; ",
				            "DELETE FROM MDB_doctorado.recom_etesi_xprg2; ",
				            "DELETE FROM MDB_doctorado.recom_etesi_xprg5; ",
				            "DELETE FROM MDB_doctorado.recom_etesi_xcurs1_SAIC; ",
				            "DELETE FROM MDB_doctorado.recom_etesi_xcurs2; ",
				            "DELETE FROM MDB_doctorado.recom_etesi_xcurs5; ",
				            "DELETE FROM MDB_doctorado.recom_prof_xprg1; ",
				            "DELETE FROM MDB_doctorado.recom_prof_xcurs1; ",
				            "DELETE FROM MDB_doctorado.recom_estud_xcurs1; ",
				            "DELETE FROM MDB_doctorado.recom_estud_xcurs2; ",
				            "DELETE FROM MDB_doctorado.recom_estud_xcurs6; ",
				            "DELETE FROM MDB_doctorado.recom_estud_xprg1; ",
				            "DELETE FROM MDB_doctorado.recom_estud_xprg4; ",
				            "DELETE FROM MDB_doctorado.Indicador_estud_v2022; ",
				            "DELETE FROM MDB_doctorado.Indicador_etesi_v2022; ",
				            "DELETE FROM MDB_doctorado.Indicador_prof; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_etesi_xprg5.csv' INTO TABLE MDB_doctorado.recom_etesi_xprg5 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_etesi_xprg2.csv' INTO TABLE MDB_doctorado.recom_etesi_xprg2 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_etesi_xprg1_SAIC.csv' INTO TABLE MDB_doctorado.recom_etesi_xprg1_SAIC "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_etesi_xcurs5.csv' INTO TABLE MDB_doctorado.recom_etesi_xcurs5 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_etesi_xcurs2.csv' INTO TABLE MDB_doctorado.recom_etesi_xcurs2 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_etesi_xcurs1_SAIC.csv' INTO TABLE MDB_doctorado.recom_etesi_xcurs1_SAIC "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",      		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_prof_xprg1.csv' INTO TABLE MDB_doctorado.recom_prof_xprg1 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_prof_xcurs1.csv' INTO TABLE MDB_doctorado.recom_prof_xcurs1 "
		            				+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",   
            				"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_estud_xprg1_2022.csv' INTO TABLE MDB_doctorado.recom_estud_xprg1 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_estud_xprg4_bloc.csv' INTO TABLE MDB_doctorado.recom_estud_xprg4 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_estud_xcurs6.csv' INTO TABLE MDB_doctorado.recom_estud_xcurs6 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",         		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_estud_xcurs2.csv' INTO TABLE MDB_doctorado.recom_estud_xcurs2 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",         		
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"recom_estud_xcurs1.csv' INTO TABLE MDB_doctorado.recom_estud_xcurs1 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"Indicador_estud_v2022.csv' INTO TABLE MDB_doctorado.Indicador_estud_v2022 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"Indicador_etesi_v2022.csv' INTO TABLE MDB_doctorado.Indicador_etesi_v2022 "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; ",
		            		"LOAD DATA LOCAL INFILE '"+pathFilesDoctorado+"Indicador_prof.csv' INTO TABLE MDB_doctorado.Indicador_prof "
				            		+ "CHARACTER SET UTF8 FIELDS TERMINATED BY ';' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGNORE 1 LINES; "
				            };
		
		Statement statement = null;
		try (Connection connection = DriverManager.getConnection(connUrl)) {
			statement = connection.createStatement();
			for(String q : queries) { statement.addBatch(q); }
			statement.executeBatch();
		}
		catch (SQLException ex) {
			sss.err("Error when connecting survey database", ex.getMessage() + System.lineSeparator() + StringUtils.join(ex.getStackTrace(), System.lineSeparator()));
            ex.printStackTrace();
            return "-1";
		}
		finally {
			if(statement != null) { statement.close(); }
		}
		
		return "1";
	}
	
}
