ETL in Java: SQL-Based Data Pipelines with Scriptella

Moving data between databases, importing CSV files, or transforming records is a common task in Java applications. The question is often not how to perform the transformation, but how much infrastructure you need around it.

You can write custom JDBC code, use a lightweight ETL tool, or adopt a batch-processing framework. Each approach has its place.

This guide compares those options and demonstrates how Scriptella, an open-source Java ETL tool, handles SQL-based data pipelines without requiring a separate ETL server or visual designer.

1. Choosing a Java ETL Approach: JDBC, Scriptella, or Spring Batch

Consider a typical ETL task: read records from one data source, transform a few fields, and write them into a PostgreSQL database.

There are several ways to implement it.

Option 1: Write custom JDBC code

JDBC gives you direct control over database access and SQL execution.

A typical data migration might involve:

  1. Open connections to the source and destination.
  2. Execute a query against the source.
  3. Iterate through the ResultSet.
  4. Transform each record.
  5. Insert records into the destination using prepared statements.
  6. Handle transactions, exceptions, and resource cleanup.

For small, application-specific jobs, this is often a reasonable choice. The code uses familiar Java APIs and doesn't require introducing a new ETL abstraction.

The tradeoff is maintenance. As the number of data sources and transformations grows, your code also needs to manage connection configuration, row iteration, batching, error handling, and execution.

If your job consists mostly of SQL, much of that Java code may be infrastructure rather than business logic.

Option 2: Use a lightweight ETL tool

A tool such as Scriptella moves the execution mechanics out of your application code.

Instead of writing a Java loop that reads and inserts rows, you declare the source and destination connections, provide SQL statements, and describe how the records flow between them.

Scriptella uses three main concepts:

These elements are declared in an XML file. SQL remains SQL; XML is used to connect the pieces.

Scriptella can work with JDBC databases, CSV, text, XML, JSON, and other supported sources. It runs as a command-line tool or can be embedded in a Java application.

This approach is useful when the main work is already expressible as SQL or simple data transformations.

The tradeoff is learning Scriptella's configuration and execution model. You still need to understand SQL, transactions, and the behavior of your data sources.

Option 3: Use a batch-processing framework

Frameworks such as Spring Batch provide a more comprehensive model for batch applications.

They include concepts such as jobs, steps, readers, processors, writers, execution metadata, and restartable processing.

This becomes valuable when a pipeline has operational requirements beyond moving data:

The additional capabilities also introduce more concepts, configuration, and lifecycle management.

If you already use Spring extensively or need those capabilities, Spring Batch may be the appropriate choice.

If your requirement is simply to execute a sequence of SQL transformations and move rows between databases, a smaller tool may be sufficient.

Comparing the approaches

ConsiderationCustom JDBCScriptellaSpring Batch
Primary abstractionJava codeSQL and ETL configurationJobs and steps
SQL supportDirectDirect through JDBCThrough JDBC-based components
Multiple data sourcesImplement integration codeBuilt-in driver modelConfigure readers and writers
Custom Java logicFull flexibilityExtensions and integrationsFull flexibility
Job restartabilityImplement yourselfRequires job-specific designFramework-supported
Execution modelApplication-definedStandalone or embeddedBatch application framework
Best fitSmall custom jobsSQL-centric ETL and migrationsOperationally complex batch processing

None of these approaches is universally better. The right choice depends on the work the pipeline must perform and the operational guarantees it requires.

For a closer comparison, see Scriptella vs Spring Batch.

2. When SQL-Based ETL Makes Sense

Many data pipelines spend most of their time performing operations databases already understand:

For these jobs, SQL can be a useful common language.

Scriptella allows a source query to feed values directly into destination SQL statements. The database performs the SQL operations, while Scriptella handles connections, row iteration, and execution.

This can simplify jobs where transformations are mostly SQL-based and don't require extensive Java application logic.

Not every transformation belongs in SQL. Complex validation, business rules, or application-specific processing may be easier to implement and maintain in Java.

The advantage of SQL-based ETL is narrower: when SQL already describes the work clearly, you may not need a custom Java program around it.

3. Java ETL Example: Import CSV into PostgreSQL

Build a small ETL job that imports customer records from a CSV file into PostgreSQL.

The objective is straightforward:

Step 1: Prepare the source data

Create a file named customers.csv:

id,name
1,Ada
2,Grace
3,Linus

The first row defines the column names. Scriptella's CSV driver makes those columns available as variables during execution.

Step 2: Define the ETL job

Save the following as import-customers.etl.xml:

<!DOCTYPE etl SYSTEM "http://scriptella.org/dtd/etl.dtd">
<etl>
    <connection
        id="source"
        driver="csv"
        url="customers.csv"/>

    <connection
        id="target"
        driver="postgresql"
        url="jdbc:postgresql://localhost:5432/demo"
        user="demo"
        password="${env.PG_PASSWORD}"
        classpath="lib/postgresql.jar"/>

    <script connection-id="target">
        CREATE TABLE IF NOT EXISTS customers (
            id INTEGER PRIMARY KEY,
            name VARCHAR(100) NOT NULL
        );
    </script>

    <query connection-id="source">
        <script connection-id="target">
            INSERT INTO customers (id, name)
            VALUES (CAST(?id AS INTEGER), ?name)
            ON CONFLICT (id)
            DO UPDATE SET name = EXCLUDED.name;
        </script>
    </query>
</etl>

The example contains two connections: one for reading CSV data and another for writing to PostgreSQL.

The first script creates the destination table if needed.

The query then reads the CSV file. For each row, Scriptella executes the nested SQL statement against PostgreSQL.

The ?id and ?name expressions are JDBC prepared-statement parameters. Values are bound rather than inserted into SQL as unescaped text.

The cast converts the CSV ID, which is bound as a string, to the integer type required by PostgreSQL.

The PostgreSQL ON CONFLICT clause makes this particular import repeatable: existing customer IDs are updated instead of causing duplicate-key errors.

These are ordinary PostgreSQL SQL expressions, not a separate Scriptella transformation language.

Step 3: Run from the command line

Install Scriptella, which requires Java 17 or newer.

For this example, you also need:

Place the JDBC driver at lib/postgresql.jar relative to the ETL file, and supply the database password through the PG_PASSWORD environment variable.

For example, the working directory can contain:

import-example/
  customers.csv
  import-customers.etl.xml
  lib/
    postgresql.jar

On macOS or Linux, run the ETL job from that directory:

scriptella.sh import-customers.etl.xml

On Windows, use scriptella.bat instead.

Step 4: Run from Java

To run the same XML configuration and input CSV from a Java application, add Scriptella 1.7.0 to your Maven dependencies:

<dependencies>
    <dependency>
        <groupId>org.scriptella</groupId>
        <artifactId>scriptella-core</artifactId>
        <version>1.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.scriptella</groupId>
        <artifactId>scriptella-drivers</artifactId>
        <version>1.7.0</version>
    </dependency>
</dependencies>

The PostgreSQL JDBC driver is also required. Keep it at lib/postgresql.jar relative to the ETL file as shown above; the XML connection loads it for both execution methods. Set PG_PASSWORD in the Java process environment.

Run this class with the ETL file in the working directory:

import java.io.File;
import scriptella.execution.EtlExecutor;

public class ImportCustomers {
    public static void main(String[] args) throws Exception {
        EtlExecutor.newExecutor(new File("import-customers.etl.xml")).execute();
    }
}

Step 5: Verify the results

You can then verify the imported records:

SELECT id, name FROM customers ORDER BY id;

Expected result:

 id | name
----+-------
  1 | Ada
  2 | Grace
  3 | Linus

Both approaches execute the same ETL configuration. You can run it from the command line or invoke it from a Java application with just a few lines of code.

This example is deliberately simple. Production imports still need appropriate validation, error handling, and transaction design.

A PostgreSQL upsert makes repeated imports safe for matching IDs, but it doesn't automatically resolve issues such as deleted source records or partially completed multi-system migrations.

What changes for database-to-database ETL?

The same execution pattern can read from one JDBC database and write to another.

For example, a source query might be:

SELECT id, TRIM(name) AS name
FROM customers
WHERE active = true;

Each resulting row exposes its columns to a nested destination script.

You can use different JDBC connections for PostgreSQL, MariaDB, MySQL, Oracle, and other supported databases.

The ETL structure stays largely the same. You change the connections, queries, and destination SQL to match your use case.

For a complete database-to-database example, see the Scriptella tutorial.

4. Performance: Scriptella vs JDBC and Native Imports

Reducing implementation code doesn't mean performance stops mattering.

Scriptella executes operations through data-source drivers, including JDBC. It introduces an execution layer around the SQL statements, and that layer has a cost.

How much does it matter?

Scriptella 1.7.0 was benchmarked against handwritten JDBC, Pandas, and native database import commands using a one-million-row CSV import.

Importing one million CSV rows

ApproachPostgreSQLMariaDB
Scriptella 1.7.08.747 s7.950 s
Handwritten JDBC7.642 s5.755 s
Pandas31.551 s20.377 s
Native import1.750 s (COPY)3.287 s (LOAD DATA LOCAL)

The benchmark used pre-created tables, no indexes or transformations, and one transaction per import. Scriptella and JDBC used batches of 1,000 rows.

These are results from a particular benchmark environment, not universal throughput guarantees. The reported values are medians of two runs.

The findings are straightforward.

Handwritten JDBC was faster than Scriptella. For PostgreSQL, the measured median difference was approximately 1.1 seconds over a million rows. Two runs are not enough to establish how stable that difference would be across repeated measurements.

Native database import commands were considerably faster. PostgreSQL COPY completed the same benchmark workload in 1.75 seconds.

This shouldn't be surprising. Native bulk-import commands use database-specific mechanisms and have different parsing and error semantics.

If the task is simply to load a CSV file into PostgreSQL as quickly as possible, COPY is an obvious option to evaluate.

If the task involves moving records across different systems, applying SQL transformations, and maintaining reusable ETL configurations, Scriptella addresses a different problem.

The relevant question is whether its execution overhead is acceptable for the job, compared with the implementation and maintenance work it saves.

These measurements are for bulk-import workloads, not the small upsert example above. They should not be interpreted as a benchmark of upsert performance.

Full methodology and reproducible results are available in the Scriptella benchmarks.

For additional context, see the PVR Labs article Importing a Million CSV Rows, which explores import approaches in a separate experiment.

For release details, see the Scriptella changelog.

5. When Scriptella Is Not the Right Choice

Scriptella is intentionally focused on scripting and ETL execution. That focus makes it practical for certain workloads, but it also defines its limits.

Continuous streaming. If your application processes a continuous stream of events with low-latency requirements, a streaming architecture is generally more appropriate than a conventional ETL job.

Distributed processing. Workloads that require distributing transformations across many machines may benefit from systems designed for distributed execution.

Complex restartable batch jobs. If a large job must persist execution state, resume from checkpoints, and coordinate sophisticated retry policies, Spring Batch provides a more suitable built-in foundation. Scriptella jobs can be designed for safe reruns, but this is not equivalent to general-purpose checkpoint-based restartability.

Database replication. For continuous one-to-one database replication, a dedicated replication or change-data-capture tool is usually a better choice.

Complex Java transformations. When most of the processing is application-specific Java logic rather than SQL or supported data-source operations, custom Java code may be simpler and easier to maintain.

Using a smaller tool is only beneficial when it matches the problem. Avoiding a framework shouldn't become a goal in itself.

6. Frequently Asked Questions

Is Scriptella still maintained?

Yes. Scriptella 1.7.0 was released in November 2026, adding improvements to SQL execution performance, JSON and JSON Lines support, execution reporting, and command-line progress reporting.

You can find the latest releases and development activity in the GitHub repository.

How is Scriptella different from Spring Batch?

Scriptella focuses on SQL-centric scripting and ETL execution. Its main building blocks are connections, queries, and scripts.

Spring Batch provides a more comprehensive framework for batch jobs, including job metadata, step coordination, restartability, and configurable retry and skip behavior.

Scriptella is a reasonable option for simpler SQL-oriented data jobs. Spring Batch is generally better suited to workflows that need more sophisticated batch-processing infrastructure.

Is Scriptella free and open source?

Yes. Scriptella is open source and distributed under the Apache License 2.0 license.

You can download the binary release, inspect the source code, and use it in commercial or noncommercial projects under the terms of that license.

7. Getting Started with Scriptella

If your workload is primarily SQL-based and doesn't require the capabilities discussed above, Scriptella may be a practical fit.

Scriptella is an open-source ETL and script execution tool for Java. Its design follows a simple principle: use SQL and the capabilities of existing data sources for the actual work, while keeping the execution and connection configuration separate.

You can run it from the command line, integrate it into a Java application, or automate it as part of an existing deployment workflow.

To explore further:

Final thoughts

Java offers several reasonable ways to build ETL pipelines.

Custom JDBC code provides flexibility and direct control. A framework such as Spring Batch provides comprehensive batch-processing infrastructure. Scriptella occupies a space between them: SQL-oriented data movement and transformation without requiring a larger execution platform.

For jobs that primarily read, transform, and write structured data, that can be a useful middle ground.

The objective is not to use the smallest tool possible. It's to use the simplest approach that meets the workload's requirements.