![](http://csvjdbc.sourceforge.net/CsvJdbcLogo.jpg)
另外,在 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">