GithubHelp home page GithubHelp logo

radiantlogic_csvjdbc's Introduction

CsvJdbc

Java CI

A Java database driver for reading comma-separated-value files.

Introduction

CsvJdbc is a read-only JDBC driver that uses Comma Separated Value (CSV) files or DBF files as database tables. It is ideal for writing data import programs or analyzing log files.

The driver enables a directory or a ZIP file containing CSV or DBF files to be accessed as though it were a database containing tables. However, as there is no real database management system behind the scenes, not all JDBC functionality is available.

Usage

The CsvJdbc driver is used just like any other JDBC driver, either in a database tool such as DBeaver or SQuirrel SQL Client, or programmatically in your own Java program using the steps below:

  1. download csvjdbc.jar and add it to the Java CLASSPATH.
  2. use DriverManager to connect to the database (the directory or ZIP file)
  3. create a statement object
  4. use the statement object to execute an SQL SELECT query
  5. the result of the query is a ResultSet

The following example puts the above steps into practice.

import java.sql.*;
import org.relique.jdbc.csv.CsvDriver;

public class DemoDriver
{
  public static void main(String[] args) throws Exception
  {
    // Create a connection to directory given as first command line
    // parameter. Driver properties are passed in URL format
    // (or alternatively in a java.utils.Properties object).
    //
    // A single connection is thread-safe for use by several threads.
    String url = "jdbc:relique:csv:" + args[0] + "?" +
      "separator=;" + "&" + "fileExtension=.txt";
    try (Connection conn = DriverManager.getConnection(url);

      // Create a Statement object to execute the query with.
      // A Statement is not thread-safe.
      Statement stmt = conn.createStatement();

      // Select the ID and NAME columns from sample.csv
      ResultSet results = stmt.executeQuery("SELECT ID,NAME FROM sample"))
    {
      // Dump out the results to a CSV file with the same format
      // using CsvJdbc helper function
      boolean append = true;
      CsvDriver.writeToCsv(results, System.out, append);
    }
  }
}

Documentation

Full documentation for CsvJdbc is found here.

Developing

Read the instructions for compiling CsvJdbc and for releasing CsvJdbc.

radiantlogic_csvjdbc's People

Contributors

simoc avatar valfirst avatar mfrasca avatar peterfokkinga avatar barogi avatar cadetd avatar shellychw avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.