java excel sql_java 读取excel把内容转换成sql写到txt

public class ReadExcelChangeTxt{

public static void main(String[] args) throws Exception {

readTable(); //读取excel 并把读取的内容写到txt文件中

}

//通过对单元格遍历的形式来获取信息 ,这里要判断单元格的类型才可以取出值

public static void readTable() throws Exception{

InputStream ips=new FileInputStream("h://test.xls");//读取的excel文件

File file = new File("h://test2.txt");//写入的txt文件

if(!file.exists()){

file.createNewFile();

}

FileWriter fw = new FileWriter(file,false);

BufferedWriter bw = new BufferedWriter(fw);

XSSFWorkbook wb=new XSSFWorkbook(ips);

XSSFSheet sheet=wb.getSheetAt(0);

for(Iterator ite=sheet.rowIterator();ite.hasNext();){

XSSFRow row=(XSSFRow)ite.next();

XSSFCell xqmc = row.getCell(1);//是从0开始取得,因为我的需求只是需要第二列和第五列,所以只读取了这两列的内容。

XSSFCell jwd = row.getCell(4);//

String str="update socialize_guizi_main set community_name='"+xqmc+"' where             concat_ws(',',longitude,latitude)='"+jwd+"';\r\n";

bw.write(str);

}

bw.close();

fw.close();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值