逸者

          2006年7月28日

          在java中使用CsvDriver讀取csv文件

          ??????? csv文件格式是用的比較多的,前幾天在網上找到一個驅動可以把這種格式的文件當作數據庫一樣讀取。
          操作步驟如下:
          第一、下載驅動程序http://sourceforge.net/projects/csvjdbc
          第二、把csvjdbc.jar文件放到classpath路徑中去。
          第三、例子如下:
          ?
          import java.sql.*;
          import org.relique.jdbc.csv.CsvDriver;
          public class JdbcCsv
          {
          public static void main(String[] args)
          {
          try
          {
          // load the driver into memory
          Class.forName("org.relique.jdbc.csv.CsvDriver");
          // create a connection. The first command line parameter is assumed to
          // be the directory in which the .csv files are held
          Connection conn = DriverManager.getConnection("jdbc:relique:csv:E:\\fund\\test\\");
          // create a Statement object to execute the query with
          Statement stmt = conn.createStatement();
          // Select the ID and NAME columns from sample.csv
          ResultSet results = stmt.executeQuery("SELECT djwd,銀行 from czcg");
          // dump out the results
          while (results.next())
          {
          System.out.println("djwd= " + results.getString("djwd") + " 銀行= " + results.getString("銀行"));
          }
          // clean up
          results.close();
          stmt.close();
          conn.close();
          }
          catch(Exception e)
          {
          System.out.println("Oops-> " + e);
          }
          }
          }

          posted @ 2006-07-28 08:55 飄逸者 閱讀(2012) | 評論 (2)編輯 收藏

          <2006年7月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆檔案

          搜索

          最新評論

          主站蜘蛛池模板: 都昌县| 青岛市| 三穗县| 罗平县| 长海县| 营山县| 安庆市| 新竹市| 镇宁| 寻乌县| 郑州市| 余姚市| 增城市| 关岭| 泽普县| 忻州市| 喀喇沁旗| 景泰县| 微博| 卢龙县| 安龙县| 施甸县| 武汉市| 扎赉特旗| 靖远县| 德庆县| 五常市| 南雄市| 全椒县| 临泽县| 江门市| 靖州| 鄄城县| 乐亭县| 宝清县| 平邑县| 都匀市| 阜康市| 新竹市| 岳普湖县| 灵寿县|