【发布时间】:2013-06-20 15:48:40
【问题描述】:
我正在尝试使用 csvjdbc 驱动程序从 csv 文件中选择不同的字段。我有一个 csv 表,例如:
id departmentcode fte
223356 DS3G5530DK 1.0
234335 ES4K44343L 0.8
435331 GS2K54534P 1.0
...
我想将列导入为 Integer、String 和 Double,所以我创建了一个 Java.Util.Properties 对象并添加了列类型:
Properties props = new Properties();
props.put("columnTypes", "Integer,String,Double");
之后我与属性对象建立连接并查询 csv:
Connection conn = DriverManager.getConnection("jdbc:relique:csv:" +getPath()+"/temp/", props);
ResultSet results = stmt.executeQuery("SELECT id, departmentcode, fte FROM tempCSV WHERE ...")
while (results.next()) {
...
System.out.println( results.getInt("id") );
System.out.println( results.getString("departmentcode") );
System.out.println( results.getDouble("fte") );
...
}
但是当我从结果中选择 DEPARTMENT-CODE 时,它始终是双精度 (0.0)。对于id 和fte,它按预期进行(因为id 是一个int 而fte 是一个double)。我的属性对象有问题吗?
【问题讨论】: