使用Jdeveloper 12C,Oracle DB 12C,Windows 8.1 这是我将Excel文件读取到DB的代码。
这是代码I
的图像FileInputStream file = new FileInputStream
(new File("E:/Company Mails.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
DCBindingContainer bindings2 = (DCBindingContainer)
BindingContext.getCurrent().getCurrentBindingsEntry();
JUCtrlHierBinding obj = (JUCtrlHierBinding)
bindings2.findCtrlBinding("CompanyMails1");
ViewObject vo = obj.getViewObject();
BindingContainer bindings = BindingContext.
getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.
getOperationBinding("Commit");
while (rowIterator.hasNext()){
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
oracle.jbo.Row r = vo.createRow();
while (cellIterator.hasNext()){
Cell cell = cellIterator.next();
r.setAttribute("No", row.getCell(0));
r.setAttribute("Mail", row.getCell(1));
r.setAttribute("Person", row.getCell(2));} }
file.close(); operationBinding.execute();}
catch (Exception e){e.printStackTrace(); }
return null;}
这是我在Jdev上得到的消息
<org.apache.myfaces.trinidad.component.UIXComponentBase> <UIXComponentBase> <getClientId> <INVALID_CALL_TO_GETCLIENTID> <oracle.adf.controller> <Utils> <buildFacesMessage> <ADF: Adding the following JSF error message: For input string: "No"> java.lang.NumberFormatException: For input string: "No" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
&#34;否&#34;因为String是Excel文件中第一列的头部 这是运行代码后出现的错误的图片。
答案 0 :(得分:0)
setAttribute()
方法需要列的索引。不是列标题。
所以你必须改为:
r.setAttribute(0, row.getCell(0));