Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JDBC Database Table Copy Tool

Keep a Changelog v1.1.0 badge Maven Central license code of conduct Quality Gate Status Coverage

Java runtime version Java build version Apache Maven

fj-copy-jdbc-db is a high-performance, robust, and highly dynamic Java utility designed to copy table data from a source database query to a destination database table using standard JDBC metadata APIs.


Features

  • Metadata-Driven Execution: Dynamically extracts column names, mappings, and database data types directly from the source query result set. No hardcoded schemas are required.
  • High-Performance Batching: Executes inserts using optimized prepared statement batches to minimize database roundtrips.
  • Robust LOB & Type Mapping: Gracefully translates standard primitive datatypes, nullable fields, and large objects (CLOB, BLOB) using native Java streams.
  • Configurable Control: Supports custom execution modes, including configurable batch sizes and optional target table truncation before copy operations.

Quickstart

Build

mvn clean install

Build & Run Tests

mvn clean install -P test

API Usage

Simple Copy

Copies all columns returned by a source query directly to the target table using default settings (batch size of 1000, no target truncation):

import java.sql.Connection;
import org.fugerit.java.db.copy.CopyJDBC;

Connection srcConn = ...;  // Source DB Connection
Connection destConn = ...; // Destination DB Connection

String srcQuery = "SELECT id, name, created_at, details FROM my_source_table";
String destTable = "my_destination_table";

int rowsCopied = CopyJDBC.copy(srcConn, destConn, srcQuery, destTable);
System.out.println("Copied " + rowsCopied + " rows successfully!");

Advanced Copy with Configurations

Use the builder options inside CopyConfig to control target truncation and customize the size of your execution batches:

import java.sql.Connection;
import org.fugerit.java.db.copy.CopyJDBC;
import org.fugerit.java.db.copy.CopyConfig;

Connection srcConn = ...;
Connection destConn = ...;

String srcQuery = "SELECT * FROM employees WHERE department = 'IT'";
String destTable = "it_employees_backup";

CopyConfig config = CopyConfig.builder()
    .batchSize(5000)        // Run prepared statements in batches of 5000
    .truncateDest(true)     // Delete all existing destination rows before copying
    .build();

int rowsCopied = CopyJDBC.copy(srcConn, destConn, srcQuery, destTable, config);
System.out.println("Copied " + rowsCopied + " rows into the backup table!");

About

Project to copy a database table from a source db to a destination db

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages