Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a h2 database from some fields of a CSV file
    primarykey
    data
    text
    <p>i would like to create a new embedded h2 database from a CSV file. Here is the snippet of the csv file</p> <blockquote> <p>Country,City,AccentCity,Region,Population,Latitude,Longitude</p> <p>ad,aixovall,Aixovall,06,,42.4666667,1.4833333</p> <p>ad,andorra,Andorra,07,,42.5,1.5166667</p> <p>ad,andorra la vella,Andorra la Vella,07,20430,42.5,1.5166667</p> <p>ad,andorra-vieille,Andorra-Vieille,07,,42.5,1.5166667</p> <p>ad,andorre,Andorre,07,,42.5,1.5166667</p> </blockquote> <p>I don't want to retrieve all the fields of the csv file. Actually, i want them all except the <em>City</em> and <em>Region</em> fields.</p> <p>And further, i want to insert the content of the csv file into the database ONLY IF the content of <em>POPULATION</em> is not empty.</p> <p>Thus, in the csv example above, we must only insert the 3rd row into the h2 table WORLDCITIES because its 'population' field is indicated.</p> <p>Here is a snippet of code i wrote. But, as you can see, it is not enough yet:</p> <pre><code>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')); </code></pre> <p>And if i understand correctly, CSVREAD create the fields using the VARCHAR type, but i want the things like this:</p> <p>COUNTRY VARCHAR(3), ACCENTCITY VARCHAR(40), POPULATION FLOAT, LATITUDE FLOAT, LONGITUDE FLOAT</p> <p>Thanks in advance for helping.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload