Recently I have a pleasure to use a CsvJdbc driver. I use a BomReader to deal with BOM characters. It works fine, but after I start to use the BomReader, it seems that the property fileExtension is ignored. With BomReader the driver can read ONLY the files with .csv extension.
For example, when I change the extension to .txt, I got the error message:
java.sql.SQLException: C:\test\datafile.csv (The system cannot find the file specified)
Here is a test case that shows the problem. Before running the test, create a folder c:/temp/ and put in a datafile.csv data file, but change the extension to .txt. The driver cannot read the file.
publicstaticvoidmain(String[]args){try{Class.forName("org.relique.jdbc.csv.CsvDriver");Propertiesprops=newProperties();props.put("fileExtension",".txt");props.put("separator",";");props.put("charset","UTF-8");CsvConnectionconn=(CsvConnection)DriverManager.getConnection("jdbc:relique:csv:class:" + BomReader.class.getName(), props); Statement stmt = conn.createStatement(); // suppose to have folder c:\test\ with CSV file "datafile.txt" ResultSet results = stmt.executeQuery("SELECT*FROMC:\\test\\datafile"); ResultSetMetaData meta = results.getMetaData(); while (results.next()) { for (int i = 0; i < meta.getColumnCount(); i++) { System.out.println(meta.getColumnName(i + 1) + ""+results.getString(i+1));}}conn.close();}catch(Exceptione){e.printStackTrace();}}
How can I fix this problem to be able to read files with other than .csv extension?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your BomReader class is opening and reading the CSV file directly.
The name of the table is passed to the BomReader.getReader(Statement, String) method. In your example, the table name is C:\test\datafile This method is opening the file and reading and returning the contents.
You need to change class BomReader to open the file with a different suffix.
The CsvJdbc fileExtension property is not used in this situation.
Hi,
Recently I have a pleasure to use a CsvJdbc driver. I use a BomReader to deal with BOM characters. It works fine, but after I start to use the BomReader, it seems that the property fileExtension is ignored. With BomReader the driver can read ONLY the files with .csv extension.
For example, when I change the extension to .txt, I got the error message:
java.sql.SQLException: C:\test\datafile.csv (The system cannot find the file specified)
Here is a test case that shows the problem. Before running the test, create a folder c:/temp/ and put in a datafile.csv data file, but change the extension to .txt. The driver cannot read the file.
How can I fix this problem to be able to read files with other than .csv extension?
Thanks.
Your BomReader class is opening and reading the CSV file directly.
The name of the table is passed to the BomReader.getReader(Statement, String) method. In your example, the table name is C:\test\datafile This method is opening the file and reading and returning the contents.
You need to change class BomReader to open the file with a different suffix.
The CsvJdbc fileExtension property is not used in this situation.
See the TableReader example in http://csvjdbc.sourceforge.net/doc.html for an example.
You are right, I completely forget about it.
Thanks a lot.