i would like to create a new embedded h2 database from a CSV file. Here is the snippet of the csv file
Country,City,AccentCity,Region,Population,Latitude,Longitude
ad,aixovall,Aixovall,06,,42.4666667,1.4833333
ad,andorra,Andorra,07,,42.5,1.5166667
ad,andorra la vella,Andorra la Vella,07,20430,42.5,1.5166667
ad,andorra-vieille,Andorra-Vieille,07,,42.5,1.5166667
ad,andorre,Andorre,07,,42.5,1.5166667
I don't want to retrieve all the fields of the csv file. Actually, i want them all except the City and Region fields.
And further, i want to insert the content of the csv file into the database ONLY IF the content of POPULATION is not empty.
Thus, in the csv example above, we must only insert the 3rd row into the h2 table WORLDCITIES because its 'population' field is indicated.
Here is a snippet of code i wrote. But, as you can see, it is not enough yet:
conn = DriverManager.getConnection(connectionURL, connectionProps);
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE WORLDCITIES"
+ " AS SELECT COUNTRY, ACCENTCITY, POPULATION, LATITUDE, LONGITUDE"
+ " FROM CSVREAD('snippet.csv'));
And if i understand correctly, CSVREAD create the fields using the VARCHAR type, but i want the things like this:
COUNTRY VARCHAR(3), ACCENTCITY VARCHAR(40), POPULATION FLOAT, LATITUDE FLOAT, LONGITUDE FLOAT
Thanks in advance for helping.