Scriptella: copy table from access to postgresql

Dirj

New Member
I'm new to scriptella, and I got totally stuck with the following problem.I have the access table given.I'm getting the table schema using program I wrote.The output file (tableschema.xml) looks like :\[code\]<?xml version="1.0" encoding="UTF-8"?><table> <column>ID</column> <datatype>COUNTER</datatype> <column>FirstName</column> <datatype>VARCHAR</datatype> <column>LastName</column> <datatype>VARCHAR</datatype> <column>Salary</column> <datatype>CURRENCY</datatype> <column>SSN</column> <datatype>INTEGER</datatype></table>\[/code\]Then, using Scriptella, I need to create a new postgresql Database (if possible. If not possible, we can assume, that DB is already created).Than i need to create a new table(required) using the xml file provided and copy all data from access table to postgresql table.I implemented data extraction from access. I implemented info extraction from xml file.I got stuck with creating the DB and table in postgres. It seems that CREATE DATABASE and CREATE TABLE just don't work through scriptella.My rough draft of etl.xml file:\[code\]<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">\[/code\]\[code\] <connection id="db1" url="jdbc:odbc:TestDB" driver="scriptella.driver.odbc.Driver" user="Dzmitry" password="a"/> <connection id="db2" url="jdbc:odbc:PostgreSQLconnector" driver="scriptella.driver.odbc.Driver" classpath="postgresql.jar" user="Dzmitry" password="a"/> <connection id="script" driver="script"/> <connection id="java" driver="scriptella.driver.janino.Driver"/> <connection id="log" driver="text"/> <!-- doesn't work <script connection-id="db2" new-tx="true" if="create_databases"> CREATE DATABASE testDB; </script> --> <query connection-id="db1"> SELECT * FROM GenInfo; <script connection-id="script"> java.lang.System.out.println("Processing row number " + rownum + " "); </script> <script connection-id="log"> ${FirstName}, ${LastName}, ${Salary}, ${SSN} </script> </query> <query connection-id="java"> import javax.xml.parsers.*; import javax.xml.xpath.*; import java.io.*; import org.w3c.dom.Document; import org.xml.sax.*; DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); File file = new File("tableschema.xml"); Document document = docBuilder.parse(file); XPathFactory xpFactory = XPathFactory.newInstance(); XPath xPath = xpFactory.newXPath(); int numberOfColumns = Integer.parseInt(xPath.evaluate("count(/table/column)", document)); for(int i = 1; i <= numberOfColumns; i++){ // does not take less than sign System.out.print("Column name " + i + ": " + xPath.evaluate("/table/column[" + i + "]", document)); System.out.println("\tData type " + i + ": " + xPath.evaluate("/table/datatype[" + i + "]", document)); } </query></etl>\[/code\]Could anybody help me?Regards,Dzmitry.
 
Back
Top