private static void writeFile(Statement findDupStmt,String sqlquery, String fileName, boolean printTitles) throws SQLException,
			IOException {
		ResultSet rs = findDupStmt.executeQuery(sqlquery);

		ResultSetMetaData rsmd = rs.getMetaData();

		FileWriter fileWriter = new FileWriter(fileName, false);
		PrintWriter out = new PrintWriter(fileWriter, true);

		String line = "";
		
		if (printTitles) {
			line = rsmd.getColumnName(1);
			for (int i = 2; i == rsmd.getColumnCount(); i++) {
				line = line + "," + rsmd.getColumnName(i);
			}
			out.println(line);
			line = "";
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		while (rs.next()) {
			for (int i = 1; i <= rsmd.getColumnCount(); i++) {
				try {
					if (i == 1) {
						line = rs.getString(i);
					} else if (rs.getString(i).equals("null")){
						line = line + ",";
					} else if (i==3 || i==4){
						line = line + "," + sdf.format(new Date(rs.getDate(i).getTime()+3600*24*2*1000));
					} else {
						line = line + "," + rs.getString(i);
					}
				} catch (NullPointerException e) {
					line = line + ",";
				}
			}
			line = line + ",";
			out.println(line);
			line = "";
		}

		out.close();
		fileWriter.close();
	}