Git Product home page Git Product logo

opencsv's People

Contributors

hyee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencsv's Issues

DirectBuffer Cleaner method issue in JDK > 1.9

When using OpenCSV with a JDK > 1.9 the following error appears on execution:

java.lang.NoSuchMethodError: 'sun.misc.Cleaner sun.nio.ch.DirectBuffer.cleaner()'
at com.opencsv.FileBuffer.close(FileBuffer.java:161)
at com.opencsv.CSVWriter.close(CSVWriter.java:382)
at com.opencsv.CSVWriter.writeAll(CSVWriter.java:281)
at com.opencsv.CSVWriter.writeAll(CSVWriter.java:244)

A similar issue can be found here apache/hadoop@5d084d7

Support S3

Its really super fast against Spool or SQL developer like exports, it will be good if S3 storage as CSV destination is supported.

Need more documentation or reference example

I am getting below error.
Could you please help putting a sample program to use opencsv?

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.OracleConnection;
import java.sql.DatabaseMetaData;


import com.opencsv.*;


public class fetchUptime {  
  /**
   *
   */

  private static final String HEADER = "SCAN_DATE,HOST_NAME,UPTIME";
  // The recommended format of a connection URL is the long format with the
  // connection descriptor.
  final static String DB_URL = "jdbc:oracle:thin:@xxxx:1521/xxxx";
  // For ATP and ADW - use the TNS Alias name along with the TNS_ADMIN when using
  // 18.3 JDBC driver
  // final static String
  // DB_URL="jdbc:oracle:thin:@wallet_dbname?TNS_ADMIN=/Users/test/wallet_dbname";
  // In case of windows, use the following URL
  // final static String
  // DB_URL="jdbc:oracle:thin:@wallet_dbname?TNS_ADMIN=C:\\Users\\test\\wallet_dbname";
  final static String DB_USER = "x";
  final static String DB_PASSWORD = "x";

  /*
   * The method gets a database connection using
   * oracle.jdbc.pool.OracleDataSource. It also sets some connection level
   * properties, such as,
   * OracleConnection.CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH,
   * OracleConnection.CONNECTION_PROPERTY_THIN_NET_CHECKSUM_TYPES, etc., There are
   * many other connection related properties. Refer to the OracleConnection
   * interface to find more.
   */
  public static void main(String args[]) throws SQLException {
    Properties info = new Properties();
    info.put(OracleConnection.CONNECTION_PROPERTY_USER_NAME, DB_USER);
    info.put(OracleConnection.CONNECTION_PROPERTY_PASSWORD, DB_PASSWORD);
    info.put(OracleConnection.CONNECTION_PROPERTY_DEFAULT_ROW_PREFETCH, "1000");

    OracleDataSource ods = new OracleDataSource();
    ods.setURL(DB_URL);
    ods.setConnectionProperties(info);

    // With AutoCloseable, the connection is closed automatically.
    try (OracleConnection connection = (OracleConnection) ods.getConnection()) {
      // Get the JDBC driver name and version
      DatabaseMetaData dbmd = connection.getMetaData();
      System.out.println("Driver Name: " + dbmd.getDriverName());
      System.out.println("Driver Version: " + dbmd.getDriverVersion());
      // Print some connection properties
      System.out.println("Default Row Prefetch Value is: " + connection.getDefaultRowPrefetch());
      System.out.println("Database Username is: " + connection.getUserName());
      System.out.println();
      // Perform a database operation
      printUptime(connection);
    }
  }

  /*
   * Displays first_name and last_name from the employees table.
   */
  public static void printUptime(Connection connection) throws SQLException {
    // Statement and ResultSet are AutoCloseable and closed automatically.
    try (Statement statement = connection.createStatement()) {
      try (ResultSet resultSet = statement
          .executeQuery("select scan_date, host_name,up_time from uptimes where rownum<10")) {
        // System.out.println("SCAN_DATE" + " " + "HOST_NAME" + " " + "UP_TIME");
        // System.out.println("---------------------");
        // while (resultSet.next())
        // System.out.println(resultSet.getString(1) + " "
        // + resultSet.getString(2) + " " + resultSet.getString(3));
        try {
          ResultSet2CSV(resultSet, "./uptimes.csv", HEADER, false);
          } catch (Exception e) {
            System.out.println("Error happened.");
          }    
      }
    }   
  } 

  public static int ResultSet2CSV(final ResultSet rs, final String fileName, final String header, final boolean aync) throws Exception {
    try (CSVWriter writer = new CSVWriter(fileName)) {
        //Define fetch size(default as 30000 rows), higher to be faster performance but takes more memory
        ResultSetHelperService.RESULT_FETCH_SIZE=10;
        //Define MAX extract rows, -1 means unlimited.
        ResultSetHelperService.MAX_FETCH_ROWS=200;
        writer.setAsyncMode(aync);
        int result = writer.writeAll(rs, true);
        return result - 1;
    }
}
}

   2019-07-16 00:43:14: 0 rows extracted, total: 0 rows, 0.00 MB, 0.001 secs on fetching.
Exception in thread "main" java.lang.AbstractMethodError: Method oracle/jdbc/driver/OracleResultSetImpl.getObject(ILjava/lang/Class;)Ljava/lang/Object; is abstract
        at oracle.jdbc.driver.OracleResultSetImpl.getObject(OracleResultSetImpl.java)
        at com.opencsv.ResultSetHelperService.getColumnValues(ResultSetHelperService.java:204)
        at com.opencsv.ResultSetHelperService.getColumnValues(ResultSetHelperService.java:159)
        at com.opencsv.CSVWriter.writeAll(CSVWriter.java:278)
        at com.opencsv.CSVWriter.writeAll(CSVWriter.java:244)
        at fetchUptime.ResultSet2CSV(fetchUptime.java:116)
        at fetchUptime.printUptime(fetchUptime.java:101)
        at fetchUptime.main(fetchUptime.java:84)

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.