Für die Beispiele wird folgende csv-Datei verwendet: Beispiel csv
jdbc-Client starten
java -jar csvjdbc/target/csvjdbc.jar
Ausgabe
Simple jdbc client, 1.0
Verbinden zum Treiber
connect 'jdbc:csv:'
Ausgabe
Connection successfully opened.
Lese die ersten 8 Rows
SELECT x,y,z
FROM "chinook.Track.csv" COLUMNS (x,y,z) SEPARATED BY '|'
WHERE rownumber <= 8;
Ausgabe
x y z
- - -
TrackId Name AlbumId
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
Lese 8 Rows
SELECT x,y,z
FROM "chinook.Track.csv" COLUMNS (x,y,z) SEPARATED BY '|'
WHERE rownumber > 1
AND rownumber <= 9;
Ausgabe
x y z
- - -
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
8 Inject The Venom 1
Lese die ersten 8 Rows
SELECT "TrackId",name,AlbumId
FROM "chinook.Track.csv" COLUMNS ("TrackId",Name,AlbumId) SEPARATED BY '|'
WHERE rownumber <= 8;
Ausgabe
TrackId name albumid
------- ---- -------
TrackId Name AlbumId
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
Lese die ersten 8 Rows
SELECT TrackId,Name,AlbumId
FROM "chinook.Track.csv" COLUMNS (trackid,Name,AlbumId) HEADLINE 1 SEPARATED BY '|'
WHERE rownumber <= 8;
Ausgabe
trackid name albumid
------- ---- -------
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
8 Inject The Venom 1
Tauscht man in der COLUMNS-Clause die Spalten Name und trackid so bekommt man das gleiche Ergebnis wie zuvor.
SELECT TrackId,Name,AlbumId
FROM "chinook.Track.csv" COLUMNS (Name,trackid,AlbumId) HEADLINE 1 SEPARATED BY '|'
WHERE rownumber <= 8;
Das passiert nicht, wenn man die Spalten mit den Kopfzeilen im csv matched (via HEADLINE 1). Somit kann der Lieferant die Reihenefolge beliebig vetrauschen, so lange die Überschriften (=Namen) in der Kopfzeile immer gleich angegeben werden
Für die Beispiele wird folgendes Excel verwendet: Beispiel Excel
jdbc-Client starten
java -jar exceljdbc/target/exceljdbc.jar
Ausgabe
Simple jdbc client, 1.0
Verbinden zum Treiber
connect 'jdbc:xlsx:'
Ausgabe
Connection successfully opened.
Lese die ersten 8 Rows
SELECT x,y,z
FROM "chinook.xlsx"."Track" COLUMNS (x,y,z)
WHERE rownumber <= 8;
Ausgabe
x y z
- - -
TrackId Name AlbumId
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
Lese die ersten 8 Rows
SELECT "TrackId","Name","AlbumId"
FROM "chinook.xlsx"."Track" COLUMNS ("TrackId","Name","AlbumId")
WHERE ROWNUMBER <= 8;
Ausgabe
TrackId Name AlbumId
------- ---- -------
TrackId Name AlbumId
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
Lese die ersten 8 Rows
SELECT TrackId,Name,AlbumId
FROM "chinook.xlsx"."Track" COLUMNS (TrackId,Name,AlbumId)
WHERE ROWNUMBER <= 8;
Ausgabe
trackid name albumid
------- ---- -------
TrackId Name AlbumId
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
Lese die ersten 8 Rows
SELECT TrackId,Name,AlbumId
FROM "chinook.xlsx"."Track" COLUMNS (TrackId,Name,AlbumId) HEADLINE 1
WHERE ROWNUMBER <= 8;
Ausgabe
trackid name albumid
------- ---- -------
1 For Those About To Rock (We Salute You) 1
2 Balls to the Wall 2
3 Fast As a Shark 3
4 Restless and Wild 3
5 Princess of the Dawn 3
6 Put The Finger On You 1
7 Let's Get It Up 1
8 Inject The Venom 1
Lese die ersten 8 Rows
SELECT Name,TrackId,Composer
FROM "chinook.xlsx"."Track" COLUMNS (TrackId,Name,Composer) HEADLINE 1
WHERE ROWNUMBER <= 8;
Ausgabe
name trackid composer
---- ------- --------
For Those About To Rock (We Salute You) 1 Angus Young, Malcolm Young, Brian Johnson
Balls to the Wall 2 null
Fast As a Shark 3 F. Baltes, S. Kaufman, U. Dirkscneider
Restless and Wild 4 F. Baltes, R.A. Smith-Diesel, S. Kaufman, U. Dirkscneider
Princess of the Dawn 5 Deaffy
Put The Finger On You 6 Angus Young, Malcolm Young, Brian Johnson
Let's Get It Up 7 Angus Young, Malcolm Young, Brian Johnson
Inject The Venom 8 Angus Young, Malcolm Young, Brian Johnson
Lese die ersten 8 Rows
SELECT Name1
FROM "chinook.xlsx"."Track" COLUMNS (TrackId,Name1,Composer) HEADLINE 1
WHERE ROWNUMBER <= 8;
Ausgabe
required column name name1 not found in xlsx file [xl/worksheets/sheet1.xml]