CSV(Comma Separated Value),CsvJdbc提供了Java訪問csv文件的驅動,它實際上是將csv當做數據庫表來進行操作,可以進行簡單的查詢。方法如下:
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);
}
}
}
posted on 2006-03-13 17:51
fadesea 閱讀(1296)
評論(0) 編輯 收藏 所屬分類:
JAVA