<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: etl code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 15:44:45 GMT</pubDate>
    <description>DZone Snippets: etl code</description>
    <item>
      <title>Using JavaScript for ETL transformations</title>
      <link>http://snippets.dzone.com/posts/show/5236</link>
      <description>&lt;a href="http://scriptella.javaforge.com"&gt;Scriptella&lt;/a&gt; provides a simple way to perform various transformations in JavaScript (or other scripting language which have a corresponding driver). &lt;br /&gt;Our example transformation consists of 3 steps:&lt;br /&gt;1) Select rows from source table.&lt;br /&gt;2) Transform a column value from number to text&lt;br /&gt;3) Insert a transformed value into a destination table.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection id="db" driver="auto" url="jdbc:hsqldb:mem:tst" user="sa" password="" classpath="../lib/hsqldb.jar"/&gt;&lt;br /&gt;    &lt;connection id="js" driver="script"/&gt; &lt;br /&gt;    &lt;connection id="log" driver="text"/&gt; &lt;!-- For printing debug information on the console --&gt;&lt;br /&gt;&lt;br /&gt;    &lt;script connection-id="db"&gt;&lt;br /&gt;        CREATE TABLE Table_In (&lt;br /&gt;            Error_Code INT&lt;br /&gt;        );&lt;br /&gt;        CREATE TABLE Table_Out (&lt;br /&gt;            Error VARCHAR(10)&lt;br /&gt;        );&lt;br /&gt;        &lt;br /&gt;        INSERT INTO Table_IN VALUES (1);&lt;br /&gt;        INSERT INTO Table_IN VALUES (7);&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;&lt;br /&gt;    &lt;query connection-id="db"&gt;&lt;br /&gt;        SELECT * FROM Table_In&lt;br /&gt;        &lt;script connection-id="log"&gt;&lt;br /&gt;            Transforming $Error_Code&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;        &lt;!-- Transformation is described as an enclosing query&lt;br /&gt;         which is executed before nested elements --&gt;&lt;br /&gt;        &lt;query connection-id="js"&gt; &lt;br /&gt;            &lt;![CDATA[&lt;br /&gt;               if (Error_Code &lt; 5) {&lt;br /&gt;                    Error_Code='WARNING'; //Set a transformed value&lt;br /&gt;               } else {&lt;br /&gt;                    Error_Code='ERROR'; //Set a transformed value&lt;br /&gt;               }&lt;br /&gt;               query.next(); //Don't forget to trigger nested scripts execution&lt;br /&gt;            ]]&gt;&lt;br /&gt;            &lt;script connection-id="db"&gt;&lt;br /&gt;                &lt;!-- Insert transformed value --&gt;&lt;br /&gt;                INSERT INTO Table_Out VALUES (?Error_Code); &lt;br /&gt;            &lt;/script&gt;&lt;br /&gt;            &lt;script connection-id="log"&gt;&lt;br /&gt;                Transformed to $Error_Code&lt;br /&gt;            &lt;/script&gt;&lt;br /&gt;        &lt;/query&gt;&lt;br /&gt;    &lt;/query&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 16 Mar 2008 12:01:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5236</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>How to execute Scriptella ETL files</title>
      <link>http://snippets.dzone.com/posts/show/4862</link>
      <description>&lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; provides several ways to execute ETL files:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Invocation from Ant&lt;/b&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;taskdef resource="antscriptella.properties" classpath="/path/to/scriptella.jar[;additional_drivers.jar]"/&gt;&lt;br /&gt;&lt;etl file="path/to/etl/file/&gt; &lt;!-- Execute ETL file from specified location --&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;b&gt;Command-Line Execution&lt;/b&gt;&lt;br /&gt;Just type scriptella to run the file named etl.xml in the current directory. Alternatively you can use Java launcher:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;java -jar scriptella.jar [arguments]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;b&gt;Executing ETL Files from Java&lt;/b&gt;&lt;br /&gt;It is extremely easy to run Scriptella ETL files from java code. Just make sure scriptella.jar is on classpath and use any of the following methods to execute an ETL file:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;EtlExecutor.newExecutor(new File("etl.xml")).execute(); //Execute etl.xml file&lt;br /&gt;EtlExecutor.newExecutor(getClass().getResource("etl.xml")).execute(); //Execute etl.xml file loaded from classpath&lt;br /&gt;EtlExecutor.newExecutor(&lt;br /&gt;    servletContext.getResource("/WEB-INF/etl.xml")).execute(); //Execute etl.xml file from web application WEB-INF dir&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;b&gt;Integration with Spring Framework&lt;/b&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;beans&gt;&lt;br /&gt;    &lt;!-- Spring beans declarations --&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!-- Spring managed bean which executes etl.xml file --&gt;&lt;br /&gt;    &lt;bean id="executor" class="scriptella.driver.spring.EtlExecutorBean"&gt;&lt;br /&gt;        &lt;property name="configLocation" value="etl.xml"/&gt;&lt;br /&gt;    &lt;/bean&gt;&lt;br /&gt;&lt;/beans&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;The usage of executor is straightforward:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;EtlExecutor exec = (EtlExecutor) beanFactory.getBean("executor");&lt;br /&gt;exec.execute();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See &lt;a href="http://scriptella.javaforge.com/docs/api/scriptella/driver/spring/package-summary.html#package_description"&gt;Spring Driver JavaDoc&lt;/a&gt; for additional details.&lt;br /&gt;</description>
      <pubDate>Fri, 07 Dec 2007 21:10:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4862</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>Splitting large Scriptella ETL files</title>
      <link>http://snippets.dzone.com/posts/show/4216</link>
      <description>The following example demonstrates how to split a large &lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; file into several parts. This example is based on a traditional XML parsed entities approach:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&lt;br /&gt;[&lt;br /&gt;    &lt;!-- Declaring the first external parsed entity to include --&gt;&lt;br /&gt;    &lt;!ENTITY part1 SYSTEM "part1.xml"&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;!-- Declaring the second external parsed entity to include --&gt;&lt;br /&gt;    &lt;!ENTITY part2 SYSTEM "part2.xml"&gt;&lt;br /&gt;]&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection driver="text"/&gt;&lt;br /&gt;&lt;br /&gt;    &lt;!-- Including file #1 --&gt;&lt;br /&gt;    &amp;part1;&lt;br /&gt;&lt;br /&gt;    &lt;script&gt;&lt;br /&gt;        content of the script&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;!-- Including file #2 --&gt;&lt;br /&gt;    &amp;part2;&lt;br /&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 27 Jun 2007 20:33:23 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4216</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>convert apache http combined logs into sql (and import it into a mysql database eventually)</title>
      <link>http://snippets.dzone.com/posts/show/3721</link>
      <description>you need to extract the data in your http server log files and put it in a database to query it with your usual tools using SQL. this perl script does just this.&lt;br /&gt;&lt;br /&gt;it was hard to find it, that's why i put it here.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl -w&lt;br /&gt;# Written by Aaron Jenson.&lt;br /&gt;# Original source: http://www.visualprose.com/software.php&lt;br /&gt;# Updated to work under Perl 5.6.1 by Edward Rudd&lt;br /&gt;# Updated 24 march 2007 by Slim Amamou &lt;slim.amamou@alpha-studios.com&gt;&lt;br /&gt;#  - output SQL with the option '--sql'&lt;br /&gt;#  - added SQL create table script to the HELP&lt;br /&gt;#&lt;br /&gt;#  NOTE : you need the TimeDate library (http://search.cpan.org/dist/TimeDate/)&lt;br /&gt;#&lt;br /&gt;use strict;&lt;br /&gt;use Getopt::Long qw(:config bundling);&lt;br /&gt;use DBI;&lt;br /&gt;use Date::Parse;&lt;br /&gt;&lt;br /&gt;my %options = ();&lt;br /&gt;my $i = 0;&lt;br /&gt;my $sql = '';&lt;br /&gt;my $valuesSql = '';&lt;br /&gt;my $line = '';&lt;br /&gt;my $dbh = 0;&lt;br /&gt;my $sth = 0;&lt;br /&gt;my @parts = ();&lt;br /&gt;my $part;&lt;br /&gt;my $TIMESTAMP = 3;&lt;br /&gt;my $REQUEST_LINE = 4;&lt;br /&gt;my @cols = (&lt;br /&gt;	'remote_host',			## 0&lt;br /&gt;	'remote_logname',		## 1&lt;br /&gt;	'remote_user',			## 2&lt;br /&gt;	'request_time',			## 3.string&lt;br /&gt;	'time_stamp',			## 3.posix&lt;br /&gt;	'request_line',			## 5&lt;br /&gt;	'request_method',		## 6&lt;br /&gt;	'request_uri',			## 7&lt;br /&gt;	'request_args',			## 8&lt;br /&gt;	'request_protocol',		## 9&lt;br /&gt;	'status',				## 10&lt;br /&gt;	'bytes_sent',			## 11&lt;br /&gt;	'referer',				## 12&lt;br /&gt;	'agent'					## 13&lt;br /&gt;);&lt;br /&gt;my $col = '';&lt;br /&gt;&lt;br /&gt;GetOptions (\%options,&lt;br /&gt;		"version" =&gt; sub { VERSION_MESSAGE(); exit 0; },&lt;br /&gt;		"help|?" =&gt; sub { HELP_MESSAGE(); exit 0; },&lt;br /&gt;		"host|h=s",&lt;br /&gt;		"database|d=s",&lt;br /&gt;		"table|t=s",&lt;br /&gt;		"username|u=s",&lt;br /&gt;		"password|p=s",&lt;br /&gt;		"logfile|f=s",&lt;br /&gt;		"sql");&lt;br /&gt;&lt;br /&gt;$options{host} ||= 'localhost';&lt;br /&gt;$options{database} ||= '';&lt;br /&gt;$options{username} ||= '';&lt;br /&gt;$options{password} ||= '';&lt;br /&gt;$options{logfile} ||= '';&lt;br /&gt;$options{sql} ||= '';&lt;br /&gt;&lt;br /&gt;if( ! ($options{database} || $options{sql}))&lt;br /&gt;{&lt;br /&gt;	HELP_MESSAGE();&lt;br /&gt;	print "Must supply a database to connect to.\n";&lt;br /&gt;	exit 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if( ! $options{table} )&lt;br /&gt;{&lt;br /&gt;	HELP_MESSAGE();&lt;br /&gt;	print "Must supply table name.\n";&lt;br /&gt;	exit 1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if( $options{logfile} )&lt;br /&gt;{&lt;br /&gt;	if( ! -e $options{logfile} )&lt;br /&gt;	{&lt;br /&gt;		print  "File '$options{logfile}' doesn't exist.\n";&lt;br /&gt;		exit 1;&lt;br /&gt;	}&lt;br /&gt;	open(STDIN, "&lt;$options{logfile}") || die "Can't open $options{logfile} for reading.";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if( $options{database} )&lt;br /&gt;{&lt;br /&gt;	$dbh = Connect();&lt;br /&gt;	if (! $dbh) {&lt;br /&gt;		exit 1;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$sql = "INSERT INTO $options{table} (";&lt;br /&gt;foreach $col (@cols)&lt;br /&gt;{&lt;br /&gt;	$sql .= "$col," if( $col );&lt;br /&gt;}&lt;br /&gt;chop($sql);&lt;br /&gt;$sql .= ') VALUES (';&lt;br /&gt;my ($linecount,$insertcount) = (0,0);&lt;br /&gt;while($line = &lt;STDIN&gt;)&lt;br /&gt;{&lt;br /&gt;	$linecount++;&lt;br /&gt;	@parts = SplitLogLine( $line );&lt;br /&gt;	next if( $parts[$TIMESTAMP+1] == 0 );&lt;br /&gt;	$valuesSql = '';&lt;br /&gt;	for( $i = 0; $i &lt; @cols; ++$i )&lt;br /&gt;	{&lt;br /&gt;		$parts[$i] =~ s/\\/\\\\/g;&lt;br /&gt;		$parts[$i] =~ s/'/\\'/g;&lt;br /&gt;		$valuesSql .= "'$parts[$i]'," if( $cols[$i] );&lt;br /&gt;	}&lt;br /&gt;	chop($valuesSql);&lt;br /&gt;&lt;br /&gt;	if( $options{database} )&lt;br /&gt;	{&lt;br /&gt;		$sth  = $dbh-&gt;prepare("$sql$valuesSql)");&lt;br /&gt;		if( ! $sth-&gt;execute() )&lt;br /&gt;		{&lt;br /&gt;			print "Unable to perform specified query.\n$sql$valuesSql\n" . $sth-&gt;errstr() . "\n";&lt;br /&gt;		} else {&lt;br /&gt;			$insertcount++;&lt;br /&gt;		}&lt;br /&gt;		$sth-&gt;finish();&lt;br /&gt;	}&lt;br /&gt;	if( $options{sql} )&lt;br /&gt;	{&lt;br /&gt;		print "$sql$valuesSql);\n";&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;if( ! $options{sql} )&lt;br /&gt;{&lt;br /&gt;	print "Parsed $linecount Log lines\n";&lt;br /&gt;	print "Inserted $insertcount records\n";&lt;br /&gt;	print "to table '$options{table}' in database '$options{database}' on '$options{host}'\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;# Connects to a MySQL database and returns the connection.&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;sub Connect&lt;br /&gt;{&lt;br /&gt;	my $dsn = "DBI:mysql:$options{database};hostname=$options{host}";&lt;br /&gt;	return DBI-&gt;connect( $dsn, $options{username}, $options{password} );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;# Splits up a log line into its parts.&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;sub SplitLogLine&lt;br /&gt;{&lt;br /&gt;	my $line = shift;&lt;br /&gt;	my $i = 0;&lt;br /&gt;	my $inQuote = 0;&lt;br /&gt;	my $char = '';&lt;br /&gt;	my $part = '';&lt;br /&gt;	my @parts = ();&lt;br /&gt;	my $count = 0;&lt;br /&gt;	chomp($line);&lt;br /&gt;	for( $i = 0; $i &lt; length($line); ++$i )&lt;br /&gt;	{&lt;br /&gt;		$char = substr($line, $i, 1);&lt;br /&gt;		if( $char eq ' ' &amp;&amp; ! $inQuote )&lt;br /&gt;		{&lt;br /&gt;			## print "Found part $part.\n";&lt;br /&gt;			if( $count == $TIMESTAMP )&lt;br /&gt;			{&lt;br /&gt;				push(@parts, "[".$part."]");&lt;br /&gt;				$part = str2time($part);&lt;br /&gt;			}&lt;br /&gt;			push(@parts, $part);&lt;br /&gt;			if( $count == $REQUEST_LINE )&lt;br /&gt;			{&lt;br /&gt;				my @request = split(/[ ?]/, $part);&lt;br /&gt;				push(@parts, $request[0]);&lt;br /&gt;				push(@parts, $request[1]);&lt;br /&gt;				if( $request[3] )&lt;br /&gt;				{&lt;br /&gt;					push(@parts, $request[2]);&lt;br /&gt;					push(@parts, $request[3]);&lt;br /&gt;				}&lt;br /&gt;				else&lt;br /&gt;				{&lt;br /&gt;					push(@parts, '');&lt;br /&gt;					push(@parts, $request[2]);&lt;br /&gt;				}&lt;br /&gt;				$count += 5;&lt;br /&gt;			}&lt;br /&gt;			else&lt;br /&gt;			{&lt;br /&gt;				++$count;&lt;br /&gt;			}&lt;br /&gt;			$part = '';&lt;br /&gt;		}&lt;br /&gt;		elsif( $char eq '"' || $char eq '[' || $char eq ']' )&lt;br /&gt;		{&lt;br /&gt;			$inQuote = !$inQuote;&lt;br /&gt;		}&lt;br /&gt;		else&lt;br /&gt;		{&lt;br /&gt;			$part .= $char;&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	push(@parts,$part) if $part;&lt;br /&gt;&lt;br /&gt;	return @parts;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;# Prints the usage/help message for this program.&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;sub HELP_MESSAGE&lt;br /&gt;{&lt;br /&gt;	print&lt;&lt;EOF;&lt;br /&gt;Imports an Apache combined log into a MySQL database.&lt;br /&gt;Usage: mysql_import_combined_log.pl -d &lt;database name&gt; -t &lt;table name&gt; [-h &lt;hostname&gt;] [-u &lt;username&gt;] [-p &lt;password&gt;] [-f &lt;filename]&lt;br /&gt; --host|-h &lt;host name&gt;         The host to connect to.  Default is localhost.&lt;br /&gt; --database|-d &lt;database name&gt; The database to use.  Required.&lt;br /&gt; --username|-u &lt;username&gt;      The user to connect as.&lt;br /&gt; --password|-p &lt;password&gt;      The user's password.&lt;br /&gt; --table|-t &lt;table name&gt;       The name of the table in which to insert data.&lt;br /&gt; --logfile|-f &lt;file name&gt;      The file to read from.  If not given, data is read from stdin.&lt;br /&gt; --sql                         Output SQL&lt;br /&gt; --help|-?                     Print out this help message.&lt;br /&gt; --version                     Print out the version of this software.&lt;br /&gt;&lt;br /&gt;----------------------------------&lt;br /&gt;-- SQL create statements for the table&lt;br /&gt;--&lt;br /&gt;&lt;br /&gt;create table &lt;TABLE_NAME&gt; (&lt;br /&gt;    remote_host varchar(50) ,&lt;br /&gt;    remote_logname varchar(50) ,&lt;br /&gt;    remote_user varchar(50) ,&lt;br /&gt;    request_time char(28),&lt;br /&gt;    time_stamp varchar(10) ,&lt;br /&gt;    request_line varchar(255),&lt;br /&gt;    request_method varchar(10) ,&lt;br /&gt;    request_uri varchar(255),&lt;br /&gt;    request_args varchar(255),&lt;br /&gt;    request_protocol varchar(10) ,&lt;br /&gt;    status varchar(10) ,&lt;br /&gt;    bytes_sent varchar(10) ,&lt;br /&gt;    referer varchar(255) ,&lt;br /&gt;    agent varchar(255)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;EOF&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;# Prints the version information for this program&lt;br /&gt;# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # &lt;br /&gt;sub VERSION_MESSAGE&lt;br /&gt;{&lt;br /&gt;	print "mysql_import_combined_log.pl version 1.2\n";&lt;br /&gt;	print "Version 1.0 Written by Aaron Jenson.\n";&lt;br /&gt;	print "Update to work with perl 5.6.1 by Edward Rudd\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;1;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 24 Mar 2007 10:40:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3721</guid>
      <author>slim (Slim Amamou)</author>
    </item>
    <item>
      <title>Importing XML into a database with Scriptella ETL</title>
      <link>http://snippets.dzone.com/posts/show/3534</link>
      <description>The following &lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; simple usage example imports RSS file into a database table.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection id="in" driver="xpath" url="http://snippets.dzone.com/rss"/&gt;&lt;br /&gt;    &lt;connection id="db" driver="hsqldb" url="jdbc:hsqldb:db/rss" user="sa" classpath="hsqldb.jar"/&gt;&lt;br /&gt;classpath="hsqldb.jar"/&gt;&lt;br /&gt;    &lt;query connection-id="in"&gt;&lt;br /&gt;        /rss/channel/item&lt;br /&gt;        &lt;script connection-id="db"&gt;&lt;br /&gt;            INSERT INTO Rss (ID, Title, Description, Link) &lt;br /&gt;            VALUES (?rownum, ?title, ?description, ?link);&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;    &lt;/query&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here is the full version of the example described above. It creates an RSS table, downloads rss file, inserts rss records into a database, converts rss.xml to a plain text file and saves it to rss.txt.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection id="in" driver="xpath" url="http://snippets.dzone.com/rss"/&gt;&lt;br /&gt;    &lt;connection id="out" driver="text" url="rss.txt"/&gt;&lt;br /&gt;    &lt;connection id="db" driver="hsqldb" url="jdbc:hsqldb:db/rss" user="sa" classpath="hsqldb.jar"/&gt;&lt;br /&gt;    &lt;script connection-id="db"&gt;&lt;br /&gt;       CREATE TABLE Rss (&lt;br /&gt;           ID Integer,&lt;br /&gt;           Title VARCHAR(255),&lt;br /&gt;           Description VARCHAR(255),   &lt;br /&gt;           Link VARCHAR(255)&lt;br /&gt;&lt;br /&gt;       )&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;    &lt;query connection-id="in"&gt;&lt;br /&gt;        /rss/channel/item&lt;br /&gt;        &lt;script connection-id="out"&gt;&lt;br /&gt;            Title: $title&lt;br /&gt;            Description: [&lt;br /&gt;            ${description.substring(0, 20)}...&lt;br /&gt;            ]&lt;br /&gt;            Link: $link&lt;br /&gt;            ----------------------------------&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;        &lt;script connection-id="db"&gt;&lt;br /&gt;            INSERT INTO Rss (ID, Title, Description, Link) &lt;br /&gt;            VALUES (?rownum, ?title, ?description, ?link);&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;    &lt;/query&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Feb 2007 19:07:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3534</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>Script to insert BLOB from file into a database</title>
      <link>http://snippets.dzone.com/posts/show/3533</link>
      <description>&lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; allows inserting files into a database. This is achieved by a simple bind variables extension syntax ?{file ...}. &lt;br /&gt;The following sample initializes table of music tracks. Each track has a DATA field containing a file loaded from an external location. File song1.mp3 is stored in the same directory as etl.xml and song2.mp3 is loaded from the web:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    &lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;    &lt;etl&gt;&lt;br /&gt;        &lt;connection driver="hsqldb" url="jdbc:hsqldb:file:tracks" user="sa" classpath="hsqldb.jar"/&gt;&lt;br /&gt;        &lt;script&gt;&lt;br /&gt;            CREATE TABLE Track (&lt;br /&gt;              ID INT,&lt;br /&gt;              ALBUM_ID INT,&lt;br /&gt;              NAME VARCHAR(100),&lt;br /&gt;              DATA LONGVARBINARY&lt;br /&gt;            );&lt;br /&gt;            &lt;!-- Inserts file with path relative to ETL script location --&gt;&lt;br /&gt;            INSERT INTO Track(id, album_id, name, data) VALUES&lt;br /&gt;                   (1, 1, 'Song1.mp3', ?{file 'song1.mp3'});&lt;br /&gt;            &lt;!-- Inserts file from an external URL--&gt;&lt;br /&gt;            INSERT INTO Track(id, album_id, name, data) VALUES&lt;br /&gt;                   (2, 2, 'Song2.mp3', ?{file 'http://musicstoresample.com/song2.mp3'});&lt;br /&gt;        &lt;/script&gt;&lt;br /&gt;    &lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 18 Feb 2007 18:26:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3533</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>Copy table from one database to another</title>
      <link>http://snippets.dzone.com/posts/show/3511</link>
      <description>This &lt;a href="http://scriptella.javaforge.com"&gt;Scriptella ETL&lt;/a&gt; script copies all rows from &lt;b&gt;Src_Table&lt;/b&gt; to &lt;b&gt;Dest_Table&lt;/b&gt;.&lt;br /&gt;&lt;b&gt;Src_Table&lt;/b&gt; contains the following columns: &lt;b&gt;id, first_name, last_name&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Dest_Table&lt;/b&gt; contains the following columns: &lt;b&gt;id, name&lt;/b&gt;&lt;br /&gt;The &lt;b&gt;name&lt;/b&gt; column of the Dest_Table is produced by a concatenation of &lt;b&gt;first_name&lt;/b&gt; and &lt;b&gt;last_name&lt;/b&gt; from the &lt;b&gt;Src_Table&lt;/b&gt;&lt;br /&gt;This example demonstrates HSQLDB-To-Oracle copy procedure, although it works between virtually any databases.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;  &lt;connection id="in" driver="hsqldb" url="jdbc:hsqldb:file:demo" &lt;br /&gt;              classpath="hsqldb.jar" user="sa"/&gt;&lt;br /&gt;  &lt;connection id="out" driver="oracle" url="jdbc:oracle:thin:@localhost:1521:ORCL" &lt;br /&gt;              classpath="ojdbc14.jar" user="scott" password="tiger"/&gt;&lt;br /&gt;  &lt;!-- Copy all table rows from one to another database --&gt;&lt;br /&gt;  &lt;query connection-id="in"&gt;&lt;br /&gt;      SELECT * FROM Src_Table --Selects all rows&lt;br /&gt;      &lt;!-- For each row executes insert --&gt;  &lt;br /&gt;      &lt;script connection-id="out"&gt; &lt;br /&gt;          INSERT INTO Dest_Table(ID, Name) &lt;br /&gt;          VALUES (?id,?{first_name+' '+last_name})&lt;br /&gt;      &lt;/script&gt;&lt;br /&gt;  &lt;/query&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Tue, 13 Feb 2007 18:06:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3511</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
    <item>
      <title>Scriptella script to shutdown HSQLDB server</title>
      <link>http://snippets.dzone.com/posts/show/3183</link>
      <description>The following snippet performs shutdown of HSQLDB database.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"&gt;&lt;br /&gt;&lt;etl&gt;&lt;br /&gt;    &lt;connection driver="hsqldb" url="jdbc:hsqldb:hsql://127.0.0.1/mydb" user="sa" classpath="hsqldb.jar"/&gt;&lt;br /&gt;    &lt;script&gt;&lt;br /&gt;        SHUTDOWN;&lt;br /&gt;    &lt;/script&gt;&lt;br /&gt;&lt;/etl&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Running Scriptella from Ant is simple:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;taskdef classpath="scriptella.jar" resource="antscriptella.properties" /&gt;&lt;br /&gt;&lt;etl file="file_path"/&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Command line launcher is even simpler:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;scriptella [file_path]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 20 Dec 2006 15:33:45 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3183</guid>
      <author>ejboy (Fyodor Kupolov)</author>
    </item>
  </channel>
</rss>
