import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class shopCSV {
public static void main(String[] args) {
List<String> sqlData = new ArrayList<>();
List<String> shopIds = new ArrayList<>();
try {
File csv = new File(“/Users/danny/Downloads/test.csv”);
BufferedReader br = new BufferedReader(new FileReader(csv));
String line = “”;
String itemUpdate =””;
while ((line = br.readLine()) != null) { //判断文件是否结束
// String item[] = line.split(“,”); //csv 逗号分隔
String item[] = line.split(“\t”);
itemUpdate =
“update DPPresales.PS_LeadShop set CityId = “+item[1]+” , DistrictId = “+item[2]+” , ShopTypeId = “+item[3]+” where ShopId = “+item[0]+”;\t”;
System.out.println(itemUpdate);
sqlData.add(itemUpdate);
}
FileWriter fw = null;
BufferedWriter bw = null;
try { //文件写入
fw = new FileWriter(“/Users/danny/Downloads/Result.txt”, true);
bw = new BufferedWriter(fw, 100);
for (String string:sqlData){
bw.write(string);
}
}catch (IOException e){
System.out.println(“写入文件出错”);
}finally {
if (bw != null){
bw.flush();
bw.close();
}
if (fw!=null)
fw.close();
}
br.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
csv文件格式:
58406375 5 619 65 | |
58416338 102 3938 50 | |
58410866 299 430 50 | |
58416245 134 331 55 |
今天的文章java读取csv文件生成 sql分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/10164.html