import java.util.ArrayList;
Wednesday, 26 August 2020
Convert array to array list and and get impact
Thursday, 20 August 2020
Thursday, 13 August 2020
timezone wise get expired company list
----------------------------------------------------------------------------------------------------------
SELECT
sh_company.company_id,
sh_timezone.tz_name,
sh_timezone.tz_id,
sh_timezone.tz_unit_hm,
CONVERT_TZ(sh_company.paywall_end_date,
sh_timezone.tz_name,
sh_timezone.tz_name) AS time,
CONVERT_TZ(sh_company.paywall_end_date,
'utc',
sh_timezone.tz_name) AS time1,
sh_company.paywall_end_date
FROM
sh_company
LEFT JOIN
sh_location ON sh_location.company_id = sh_company.company_id
LEFT JOIN
sh_timezone ON sh_timezone.tz_id = sh_location.tz_id
WHERE
paywall_status = 'INACTIVE'
AND CONVERT_TZ(paywall_end_date,
sh_timezone.tz_name,
sh_timezone.tz_name) <= CONVERT_TZ('2020-08-14 23:59:59',
'utc',
sh_timezone.tz_name)
AND paywall_end_date != '0000-00-00 00:00:00'
AND name != '1Huddle'
AND sh_location.head_location = 1;
-------------------------------------------------------------------------------------------------------------
Wednesday, 5 August 2020
Thursday, 25 June 2020
CSV read and write using apache common csv
Reading a CSV file (Access Values by Names assigned to each column)
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
public class CSVReaderWithManualHeader {
private static final String SAMPLE_CSV_FILE_PATH = "./users.csv";
public static void main(String[] args) throws IOException {
try (
Reader reader = Files.newBufferedReader(Paths.get(SAMPLE_CSV_FILE_PATH));
CSVParser csvParser = new CSVParser(reader, CSVFormat.DEFAULT
.withHeader("Name", "Email", "Phone", "Country")
.withIgnoreHeaderCase()
.withTrim());
) {
for (CSVRecord csvRecord : csvParser) {
// Accessing values by the names assigned to each column
String name = csvRecord.get("Name");
String email = csvRecord.get("Email");
String phone = csvRecord.get("Phone");
String country = csvRecord.get("Country");
System.out.println("Record No - " + csvRecord.getRecordNumber());
System.out.println("---------------");
System.out.println("Name : " + name);
System.out.println("Email : " + email);
System.out.println("Phone : " + phone);
System.out.println("Country : " + country);
System.out.println("---------------\n\n");
}
}
}
}
Generating a CSV file
Finally, Let’s see an example of generating a CSV file with Apache Commons CSV.
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
public class CSVWriter {
private static final String SAMPLE_CSV_FILE = "./sample.csv";
public static void main(String[] args) throws IOException {
try (
BufferedWriter writer = Files.newBufferedWriter(Paths.get(SAMPLE_CSV_FILE));
CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT
.withHeader("ID", "Name", "Designation", "Company"));
) {
csvPrinter.printRecord("1", "Sundar Pichai ♥", "CEO", "Google");
csvPrinter.printRecord("2", "Satya Nadella", "CEO", "Microsoft");
csvPrinter.printRecord("3", "Tim cook", "CEO", "Apple");
csvPrinter.printRecord(Arrays.asList("4", "Mark Zuckerberg", "CEO", "Facebook"));
csvPrinter.flush();
}
}
}
The above program will generate the following CSV file -
ID,Name,Designation,Company
1,Sundar Pichai ♥,CEO,Google
2,Satya Nadella,CEO,Microsoft
3,Tim cook,CEO,Apple
4,Mark Zuckerberg,CEO,Facebook