1、TaoCanXinXiImportAction.java
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import net.hlj.cms.gnet.model.TaoCanXinXiModel;
import net.hlj.cms.gnet.service.TaoCanXinXiImportService;
import net.hlj.cms.gnet.service.imp.TaoCanXinXiImportServiceImpl;
import net.hlj.cms.gnet.util.UtilTool;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
/**
* @项目名:保密
* @包名:保密
* @文件名:TaoCanXinXiImportAction.java
* @日期:Dec 23, 2010 3:54:16 PM
* @备注:保密
* @作者:apple
*/
public class TaoCanXinXiImportAction {
/**
* @param args
*/
public static void main(String[] args)
{
String fileName="prcpln.csv";//文件名或者prcpln.txt格式
String path="D:\\net\\";//路径
ApplicationContext ctx = new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/applicationContext.xml");//spring 上下文
TaoCanXinXiImportService server=new TaoCanXinXiImportServiceImpl();//接口
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(path+fileName), "GBK"));
String fileContext=null;
try {
while((fileContext=in.readLine())!=null)
{
String[] strs=fileContext.split("\\|");
if(strs.length==6)
{
TaoCanXinXiModel obj=new TaoCanXinXiModel();
obj.setId(UtilTool.getUUID());
obj.setName(strs[1].trim());
obj.setType("");
obj.setCode(strs[0].trim());
obj.setCpsspp("");
obj.setCpjdms(strs[2].trim());
obj.setTc_id("");
obj.setFlag("");
obj.setStatus("");
obj.setProvince("");
obj.setCity("");
obj.setArea(strs[3].trim());
obj.setCpqxsj(strs[4].trim());
obj.setCpsxsj(strs[5].trim());
obj.setNettype("0");
obj.setScv("");
obj.setFrameworkid("");
try {
if(server.isTaoCanXinXi(obj, ctx))
{
int uflag=server.taoCanXinXiUpdate(obj, ctx);
if(uflag>0)
{
System.out.println("第"+strs[0].trim()+"行数据修改成功");
}
else
{
System.out.println("第"+strs[0].trim()+"行数据修改失败");
}
}
else
{
int aflag=server.taoCanXinXiAdd(obj, ctx);
if(aflag>0)
{
System.out.println("第"+strs[0].trim()+"行数据新增成功");
}
else
{
System.out.println("第"+strs[0].trim()+"行数据新增失败");
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}