What is the best method to import a fixwidth file into a table with scriptella?
Textfile:
blabla bloblo ble bli
Columnwidth:
(1,7) (8,14) (15,21) (22,24)
Table:
T_IMPORT (
FIELD1 VARCHAR(8),
FIELD2 VARCHAR(8),
FIELD3 VARCHAR(8),
FIELD4 VARCHAR(4)
)
The solution I came up is:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<connection id="database" url="jdbc:hsqldb:mem:mymemdb" user="SA" password=""/>
<connection id="in" driver="text" url="${filePath}test_import.txt" />
<query connection-id="in">
<script connection-id="database">
INSERT INTO T_IMPORT
VALUES (
?{column0.substring(0,7)},
?{column0.substring(8,14)},
?{column0.substring(15,21)},
?{column0.substring(22,24)});
</script>
</query>
</etl>