Scriptella vs Spring Batch
Use Scriptella when SQL and simple mappings do most of the work and you can replay a failed load. Use Spring Batch when you want persisted job history, checkpoint-based restart, or Java processing and Spring services inside the job.
The same CSV-to-PostgreSQL import
A supplier sends a nightly contacts.csv with id,name,email headers. Both examples load it into public.csv_contacts and update the existing name and email on a matching ID. Use the same input, JDBC driver, and table schema from the CSV import guide. The primary key makes replaying the file leave the same contact data.
Scriptella 1.7.0
Save this as import.etl.xml next to the CSV and run scriptella.sh import.etl.xml. Replace the demo credentials or use the environment-variable form from the guide.
<!DOCTYPE etl SYSTEM "http://scriptella.org/dtd/etl.dtd">
<etl>
<connection id="source" driver="csv" url="contacts.csv">
encoding=UTF-8
</connection>
<connection id="target" driver="postgresql"
url="jdbc:postgresql://localhost:5432/demo"
user="DEMO_USER"
password="DEMO_PASSWORD"
classpath="lib/postgresql-42.7.13.jar"/>
<query connection-id="source">
<script connection-id="target">
INSERT INTO public.csv_contacts (id, name, email)
VALUES (CAST(?id AS integer), ?name, ?email)
ON CONFLICT (id) DO UPDATE
SET name = EXCLUDED.name, email = EXCLUDED.email;
</script>
</query>
</etl>
Spring Batch 6.0
This job bean belongs in a Spring configuration class. The example omits imports, application startup, and infrastructure setup. Supply a PostgreSQL DataSource, a transaction manager for it, and a JDBC JobRepository with its metadata schema initialized. For this example, use the same data source and transaction manager for the business writes and repository. Launch the job with an identifying delivery ID and retain the input file for restart. In a recurring deployment, resolve the file path from the delivery ID, for example with a step-scoped reader. See the JobRepository documentation.
record Contact(int id, String name, String email) {}
@Bean
Job importContacts(JobRepository repository, DataSource dataSource,
PlatformTransactionManager transactions) {
var reader = new FlatFileItemReaderBuilder<Contact>()
.name("contactsReader")
.resource(new FileSystemResource("contacts.csv"))
.encoding("UTF-8")
.linesToSkip(1)
.delimited().names("id", "name", "email")
.fieldSetMapper(fields -> new Contact(
fields.readInt("id"), fields.readString("name"), fields.readString("email")))
.saveState(true)
.build();
var writer = new JdbcBatchItemWriterBuilder<Contact>()
.dataSource(dataSource)
.sql("""
INSERT INTO public.csv_contacts (id, name, email)
VALUES (?, ?, ?)
ON CONFLICT (id) DO UPDATE
SET name = EXCLUDED.name, email = EXCLUDED.email
""")
.itemPreparedStatementSetter((contact, statement) -> {
statement.setInt(1, contact.id());
statement.setString(2, contact.name());
statement.setString(3, contact.email());
})
.build();
var step = new StepBuilder("loadContacts", repository)
.<Contact, Contact>chunk(100)
.transactionManager(transactions)
.reader(reader)
.writer(writer)
.build();
return new JobBuilder("importContacts", repository).start(step).build();
}
What happens if the job fails?
Suppose a temporary database error stops the load while writing row 251. With the Scriptella configuration above, the PostgreSQL transaction rolls back and a new run reads the file from the beginning. Spring Batch has already committed rows 1–200. When you restart the same failed job instance with the same input and the reader state intact, the step starts again at row 201. The example fails the step on an error. Retry and skip rules are separate configuration choices. See the Spring Batch restart documentation.
Comparison at a glance
| Decision | Scriptella 1.7.0 | Spring Batch 6.0 |
|---|---|---|
| Job definition | XML connections, queries, and scripts | Spring-managed jobs, steps, readers, and writers |
| Commit boundary | One PostgreSQL transaction in this example. JDBC batching and intermediate commits can be configured separately. | One transaction per chunk of up to 100 contacts in this example |
| Recovery state | Replay the input or track progress explicitly. | A persistent repository and stateful reader support checkpoint-based restart. |
| Error policy | Define SQL or script behavior and handle whole-job retries in the launcher or scheduler. | Configure retry or skip policies for selected exceptions. |
| Concurrent work | Split independent ETL runs and coordinate them externally. | Run independent steps in parallel or partition a step into separate worker executions. |
Which should you choose?
Choose Scriptella for a standalone import or export when the transformation fits naturally in SQL and recovery can be a safe replay. If you configure intermediate commits, earlier commits survive a later failure. The upsert makes this import replayable, and any additional side effects need their own replay strategy. See the Scriptella JDBC reference.
Choose Spring Batch when operators need job history and restart, or the steps need managed data sources, transactions, and Java domain services. For larger workloads, independent flows can run in parallel, and partitioned steps can assign separate files or nonoverlapping key ranges to workers. Those options help when work can be divided and the database, connection pool, and input can sustain the concurrency. Measure throughput and contention on your workload. See the Spring Batch scaling guide.
Using both together
If Spring Batch already coordinates a larger job, register a Tasklet that invokes the existing ETL file through scriptella.execution.EtlExecutor. Add Scriptella and its runtime drivers to the application and wire this bean into a tasklet step. The relative import.etl.xml path is resolved from the application’s working directory.
@Bean
Tasklet importWithScriptella() {
return (contribution, chunkContext) -> {
EtlExecutor.newExecutor(new File("import.etl.xml")).execute();
return RepeatStatus.FINISHED;
};
}
Let exceptions propagate so Spring Batch records a failed step. Restarting that failed step ordinarily reruns the entire ETL file. The Tasklet adds step-level status, while the ETL retains its own connection and commit boundaries. With the JDBC connection shown above, Scriptella’s commits are independent of the Spring Batch step transaction. Keep the operation safe to replay if the ETL commits before the step status is recorded. See the Spring Batch Tasklet documentation and Scriptella Java API.