CsvJdbc - Java 访问csv 文件的的JDBC驱动

CSV(Comma Separated Value),Foxmail 和 Outlook 导出的地址本都可以是 csv 文件。 CsvJdbc 提供了Java 访问 csv 文件的的 JDBC 驱动,它其实是把一个 csv 文件当做一个数据库表来操作,提供简单的查询。

另外,在 CsvJDBC 的基础上衍生了另一个开源项目, XLSJDBC,看名字就知道,XLSJDBC 是访问 xls 文件的 JDBC 驱动。

CsvJdbc 和 XLSJDBC 都只提供只读的方式,意味着只能SELECT,不能 UPDATE 和 DELETE。
以下是使用的例子:

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);
    }
  }
}

转自: http://www.sentom.net

<script type="text/javascript"> <!-- google_ad_client = "pub-4465827781731051"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; //--> </script><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4465827781731051&dt=1125637635921&format=468x60_as&output=html&ad_type=text_image&nloc=http://blog.csdn.net/fckeditor/editor/fckeditor.html?InstanceName=Editor_Edit_FCKEditor&Toolbar=Default&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=16&u_tz=540&u_his=9&u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="65535">
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值