posts - 431,  comments - 344,  trackbacks - 0
           

          About 


          CsvJdbc is a simple read-only JDBC driver that uses Comma Separated Value (CSV) files as database tables. It is ideal for writing data importing programs

          How is it used


          The CsvJDBC driver is used just like any other JDBC driver. This example code shows how the driver is used.

          import Java.sql.*;

          public class DemoDriver

          {

           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:" + args[0] );

                // 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 ID,NAME FROM sample");

                // dump out the results

                while (results.next())

                {

                  System.out.println("ID= " + results.getString("ID") + "   NAME= " + results.getString("NAME"));

                }

                // clean up

                results.close();

                stmt.close();

                conn.close();

              }

              catch(Exception e)

              {

                System.out.println("Oops-> " + e);

              }

           }

          }

          Advanced Options 


          The driver also supports a number of parameters that change the default behaviour of the driver.

          These properties are:

          separator

          Used to specify a different column separator (Default is ',').

          suppressHeaders

          Used to specify if the first line contains column header information (Default is false; column headers are on first line).

          fileExtension

          Used to specify a different file extension (Default is ".csv")

          This following example code shows how these properties are used.

           ...

           Properties props = new Java.util.Properties();

           props.put("separator","|");              // separator is a bar

           props.put("suppressHeaders","true");     // first line contains data

           props.put("fileExtension",".txt");       // file extension is .txt

           Connection conn = Drivermanager.getConnection("jdbc:relique:csv:" + args[0],props)

           ...

          Download 


          The latest version of the software can be found at http://www.sourceforge.net/projects/csvjdbc.

          posted on 2008-03-19 13:43 周銳 閱讀(337) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 章丘市| 曲周县| 乐平市| 富宁县| 常山县| 高雄市| 尉犁县| 郎溪县| 峨边| 枝江市| 临城县| 太康县| 福贡县| 富锦市| 滨州市| 浏阳市| 连平县| 永登县| 乌拉特前旗| 武胜县| 车致| 中西区| 梁山县| 高密市| 抚远县| 沧源| 商南县| 阳朔县| 永济市| 且末县| 桐梓县| 东兴市| 无锡市| 高雄县| 黄冈市| 贞丰县| 灵寿县| 枣阳市| 临沧市| 莎车县| 河间市|