日期:2014-05-20  浏览次数:20693 次

将数据插入到csv中的问题。在线等待!
现在,我又一段这样的代码,可以查询出csv文件中的数据,但是插入不了,请各位帮帮忙!
import java.sql.*;
public class TestCsvOut {

/**
* @param args
*/
public static void main(String[] args) {

// TODO 自動生成されたメソッド?スタブ
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:C:\\");

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

String strSql ="INSERT INTO sample(ID,NAME) VALUES(5,name5)";
stmt.execute(strSql);

// clean up
results.close();
stmt.close(); 
conn.close();

} catch (Exception e) {
System.out.println("Oops-> " + e);
}
}
}


------解决方案--------------------
...........csv还用driver...
很好,很强大
------解决方案--------------------
csv文件数据项之间是用逗号分开的