2

I am using http://csvjdbc.sourceforge.net/doc.html to treat CSV files on disk (e.g. 'myFile' in 'myDir') as an SQL DB I can query with SQL syntax:

// create connection
Class.forName("org.relique.jdbc.csv.CsvDriver");
Properties props = new Properties();
props.put("separator", ";");
Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + myDir, props);

// run query
Statement stmt = conn.createStatement();
ResultSet myData = stmt.executeQuery("SELECT * FROM \"" + myFile + "\"");

This works fine, but I run into trouble when the CSV file does not have a header. In that case, the first data line is considered as header and thus not read like the other data lines.

Is there any way to tell the query not to look for a header and treat the first line as data input?

2
  • 2
    props.put("suppressHeaders", "true"); Commented May 9, 2017 at 7:57
  • Thank you, that does it indeed! :) Commented May 9, 2017 at 8:03

1 Answer 1

3

Did you try setting the property suppressHeaders as listed in DemoDriver4

Properties props = new Properties();
// Define column names and column data types here.
props.put("suppressHeaders", "true");
props.put("headerline", "ID,ANGLE,MEASUREDATE");
props.put("columnTypes", "Int,Double,Date");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.