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

<!-- 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 =""; //--> <iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4465827781731051&amp;dt=1125637635921&amp;format=468x60_as&amp;output=html&amp;ad_type=text_image&amp;nloc=http://blog.csdn.net/fckeditor/editor/fckeditor.html?InstanceName=Editor_Edit_FCKEditor&amp;Toolbar=Default&amp;u_h=768&amp;u_w=1024&amp;u_ah=740&amp;u_aw=1024&amp;u_cd=16&amp;u_tz=540&amp;u_his=9&amp;u_java=true" frameborder="0" width="468" scrolling="no" height="60" allowtransparency="65535"></iframe>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值