csvjdbc读取csv文件乱码
如题,请问有什么可以解决的?
csvjdbc jar:http://txspace.2.taohuacun.cn/csvjdbc.jar
csv文件:http://txspace.2.taohuacun.cn/csv.csv
import java.io.UnsupportedEncodingException;import java.net.URLDecoder;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Properties;public class Main { public static void main(String[] args) { try { String csvFilePath = URLDecoder.decode(Main.class.getResource( "基础数据").getPath(), "UTF-8"); Connection conn = Main.getCSVConnection(csvFilePath); if (conn != null) { Statement stmt = conn.createStatement(); String sql = "select * from 车辆"; ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { System.out.println(rs.getString(1)); } } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } public static Connection getCSVConnection(String csvFilePath) { Connection conn = null; try { Class.forName("org.relique.jdbc.csv.CsvDriver"); Properties props = new java.util.Properties();// props.put("separator", "|"); props.put("suppressHeaders", "true");// props.put("fileExtension", ".txt"); // props.put("charset", "ISO-8859-2"); // props.put("maxFileSize", 10000); // props.put("create", "true"); // props.put("lineBreakEscape", "ELB"); // props.put("carriageReturnEscape", "ECR"); // props.put("useQuotes", "true"); conn = DriverManager.getConnection("jdbc:relique:csv:" + csvFilePath, props); } catch (SQLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return conn; }}