Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jferard/pgloaderutils
Some utillities for loading csv data into a PosgtreSQL database
https://github.com/jferard/pgloaderutils
Last synced: 1 day ago
JSON representation
Some utillities for loading csv data into a PosgtreSQL database
- Host: GitHub
- URL: https://github.com/jferard/pgloaderutils
- Owner: jferard
- Created: 2016-06-27T19:06:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-05T16:58:10.000Z (11 months ago)
- Last Synced: 2024-03-05T18:01:06.818Z (11 months ago)
- Language: Java
- Size: 463 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://app.travis-ci.com/jferard/pgloaderutils.svg?branch=master)](https://travis-ci.com/github/jferard/pgloaderutils)
[![Code Coverage](https://img.shields.io/codecov/c/github/jferard/pgloaderutils/master.svg)](https://codecov.io/github/jferard/pgloaderutils?branch=master)# pgLoader Utils
(C) J. Férard 2016-2018 & 2020-2022Some utilities for loading csv data into a PostgreSQL database: detect file encoding, CSV format and populate database, under GPL v3.
## Presentation
pgLoader Utils is a small set of classes to make PostgreSQL bulk load simpler.
It allows to process the CSV file on the fly (e.g. to format dates).The CSV Sniffer part is a slow but (I hope) reliable sniffer that detects, for a given CSV file :
- its encoding, among three values : ASCII, UTF-8, "other" ;
- its delimiter char, quote char and escape char ;
- whether it has or not a header.## Usage
Here is an example:try {
Class.forName("org.postgresql.Driver");
try {
Connection connection = DriverManager.getConnection(
"jdbc:postgresql://127.0.0.1:5432/testdb", "postgres",
"postgres");
try {
Statement statement = connection.createStatement();
statement.executeUpdate(
"DROP TABLE IF EXISTS testtable");
statement.executeUpdate(
"CREATE TABLE testtable ("
+ "col1 text," + "col2 decimal,"
+ "col3 text)");CSVLoaderForPostgreSQL loader = CSVLoaderForPostgreSQL
.toTable("testtable");
final StringReader stringReader = new StringReader("\"a\", 1.0, \"b,c\"\n"
+ "\"d\", 2.0, \"f,g\"\n");
final CSVSimpleFileReader csvReader = new CSVSimpleFileReader(
stringReader, Logger.getLogger(""), 16);
loader.populate(connection,
csvReader);
} finally {
connection.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}