
性能不会损耗太大,速度也比其他数据库快,且专门存储电影、图片等内容。
据说香港的马会录象全部是存储的。
明白啥指定json我建议:请选择Excel文件(.):
Excel文件标题(表)占行:
2、UploadExcelFileAction接收、写入台指定目录(局部代码)
FileOutputStream fos = null
try {
//文件数据(数组)
byte[] fileDate = ff.getFileData()
//服务器硬盘文件夹绝路径
ServletContext application = this.getServlet().getServletContext()
String realPath = application.getRealPath("/")
if(excelType==null||excelType.equals("xlsx"))//默认2007版本格式
fos = new FileOutputStream(realPath+"aircraftExcelTable.xlsx")
else
fos = new FileOutputStream(realPath+"aircraftExcelTable.xls")
fos.write(fileDate)
fos.close()
if(excelType==null||excelType.equals("xlsx"))//默认2007版本格式
num=ReadExcelSaveToDB.ReadAndSaveNew(realPath+"aircraftExcelTable.xlsx",topicNumber)
else
num=ReadExcelSaveToDB.ReadAndSave(realPath+"aircraftExcelTable.xls",topicNumber)
if(num==-1){
session.setAttribute("forwardPage", currentPage)
session.setAttribute("prompt", "文件传输失败或连接数据库")
return mapping.findForward("promptpage")
}else if(num==-2){
session.setAttribute("forwardPage", currentPage)
session.setAttribute("prompt", "Excel文件于1000条或能识别重新制作Excel文件")
return mapping.findForward("promptpage")
}else if(num==-3){
session.setAttribute("forwardPage", currentPage)
session.setAttribute("prompt", "Excel文件包含非字符(非数字)请修重试")
return mapping.findForward("promptpage")
}
} catch (FileNotFoundException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}finally{
try {
fos.close()
} catch (IOException e) {
e.printStackTrace()
}
}
3、解析读取表数据(POI)并存入数据库(局部代码)
public static int ReadAndSave(String path,String topicNumber){
try {
File file=new File(path)
FileInputStream fs=new FileInputStream(file)
@SuppressWarnings("resource")
HSSFWorkbook workbook=new HSSFWorkbook(fs)
//共几张表
int sheet_num=workbook.getNumberOfSheets()
setSheetNumber(0)
setProcess(0)//始
//循环每表
for(int i=0i<sheet_numi++){
HSSFSheet sheet=workbook.getSheetAt(i)
setSheetNumber(i+1)
if(sheet!=null&&sheet.getPhysicalNumberOfRows()!=0){
int topicNumberNum=Integer.parseInt(topicNumber)//越首行标题()
totalNumber=sheet.getPhysicalNumberOfRows()-topicNumberNum
//循环各行
for(int j=sheet.getFirstRowNum()+topicNumberNumj<=sheet.getPhysicalNumberOfRows()j++){
HSSFRow row=sheet.getRow(j)
String aircraft=null
//String aircraftType=null
Double takeoffWeight=0.00
Double payloadMax2=0.00
int seatNumberMax2=0
if(row!=null&&row.getPhysicalNumberOfCells()!=0){
switch(row.getCell(0).getCellType()){
case Cell.CELL_TYPE_STRING:
aircraft=(row.getCell(0).getStringCellValue()).trim()
break
case Cell.CELL_TYPE_NUMERIC:
aircraft=String.valueOf(row.getCell(0).getNumericCellValue()).trim()
break
}
//继续处理其单元格、行
}
//存入数据库
AircraftTableActionForm atb=new AircraftTableActionForm()
if(aircraft!=null&&!aircraft.equals("")){
atb.setAircraft(aircraft)
//set其值
updateByExcel(atb)!=-1
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)