Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Source JDBC driver for Excel, CSV files on a Maven repo

Is there an Open Source Excel/CSV/XML files JDBC driver available on a Maven repository? The JDBC-ODBC bridge mechanism is very cumbersome and does not support DataSource well (Optional feature not implemented exception). Read/write ability is essential, but read-only will do if there's nothing better.

like image 203
Shantanu Kumar Avatar asked Dec 03 '25 06:12

Shantanu Kumar


1 Answers

CsvJdbc is a Java database driver for reading comma-separated-value files.

http://csvjdbc.sourceforge.net/

Maven Repo:

<dependency>
  <groupId>net.sourceforge.csvjdbc</groupId>
  <artifactId>csvjdbc</artifactId>
  <version>1.0.9</version>
</dependency>

Usage Example:

import java.sql.*;

public class DemoDriver
{
  public static void main(String[] args)
  {
    try
    {
      // Load the driver.
      Class.forName("org.relique.jdbc.csv.CsvDriver");

      // Create a connection. The first command line parameter is
      // the directory containing the .csv files.
      // A single connection is thread-safe for use by several threads.
      Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + args[0]);

      // 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);

      // Clean up
      conn.close();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}
like image 109
rekinyz Avatar answered Dec 06 '25 17:12

rekinyz