MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 求一将Excel的数据导到数据库中的程序,紧急待中

求一将Excel的数据导到数据库中的程序,紧急待中(2)

www.MyException.Cn  网友分享于:2013-01-31  浏览:17次



OutputStream streamOut =new FileOutputStream(dir+ "/ "+sfname);
int c;
while ((c = streamIn.read()) != -1)
{
streamOut.write(c);
}
streamOut.close();
streamIn.close();

hff.setFname(fname);
hff.setSize(size);
file.destroy();

String fileToBeRead=dir+ "\\ "+sfname;
FileInputStream fs =new FileInputStream(fileToBeRead);
Connection conn=null;
PreparedStatement stmt=null;

PreparedStatement stmt1=null;
PreparedStatement stmt2=null;
PreparedStatement st=null;

Statement statement=null;
ResultSet rs=null;
String shopId= " ";
String orgId= " ";
int oid=-1;
String prodId= " ";
String state= " ";
String shopLevel= " ";
String checkDate= " ";
String temp1= " ";
// String temp2= " ";
// double amount=0;
HSSFCell cell0 =null;
HSSFCell cell1 =null;
HSSFCell cell2 =null;
HSSFCell cell3=null;
HSSFCell cell4=null;
HSSFRow aRow=null;
List arr=new ArrayList();
// List shopArr=new ArrayList();
// List orgArr=new ArrayList();
HSSFWorkbook workbook=null;
int numOfSheets=0;
short k=5;
short colNum=5;


try
{
conn=DataBaseMgr.getSalesConnection();
statement=conn.createStatement();
rs=statement.executeQuery( "select max(checkdate) as checkdate from cmm_shop_import_checkdate ");
if (rs.next()){
checkDate=rs.getString( "checkdate ");
}else{
errors.add( "必须设置普查时间 ");
return mapping.getInputForward();
}




st=conn.prepareStatement( "select prod_id from V_PRODUCT_DIS where prod_name=? ");
workbook = new HSSFWorkbook(fs);
numOfSheets=workbook.getNumberOfSheets();
for(int numSheets = 0; numSheets < numOfSheets; numSheets++)
{

if(null != workbook.getSheetAt(numSheets))
{


HSSFSheet aSheet = workbook.getSheetAt(numSheets);
aRow=aSheet.getRow(0);
if (aRow==null)
continue;
colNum=5;
if (numSheets==0){
while((aRow.getCell(colNum)!=null)&&(!aRow.getCell(colNum).getStringCellValue().toString().trim().equals( " ")))
{


colNum++;


}
colNum--;

if (aRow!=null){

for( k=4;k <=colNum;k++){
prodId=aRow.getCell(k).getStringCellValue().toString();
st.setString(1,prodId);
rs=st.executeQuery();
if (rs.next()){
arr.add(rs.getString( "prod_id "));

}else{
errors.add( "第 "+(numSheets+1)+ "个sheet的第 " + (k + 1) + "列 " + "产品型号不存在! ");
}
}
}
}
stmt=conn.prepareStatement( "select org_id,sh_id from cmm_v_shop_org where org_name=? and sh_name=? ");
// stmt1=conn.prepareStatement( "select sh_id from EB_SHOP where SH_NAME=? ");
stmt2=conn.prepareStatement( "select shopid as amount from cmm_shop_import where shopid=? and checkdate=? and orgid=? ");

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有