This discussion is archived
2 Replies Latest reply: Aug 2, 2010 11:18 AM by 800387 RSS

Convert long String with Integers to Long throwing a NumberFormatException

843810 Newbie
Currently Being Moderated
I am working working on extracting some excel data and for the most part the snippet I have below works fine and write to the database columns with out any issue. But I just started to get Number Format Exception when I extract the excel sheet with bit longer String that contains integers. I thought java Long primitive has 8 bit capacity. So I am trying to figure what I am doing wrong. It will be great if I could get any feed back on this.

FYI: I am using JavaExcel API, and I know it has nothing to do with this error because so far I have imported close 15 excel spread sheets and only different between those file and this file is that the String that is getting converted has more integers in it.

Exception in thread "main" java.lang.NumberFormatException: For input string: "525335710301092000000"
     at java.lang.NumberFormatException.forInputString(
     at java.lang.Long.parseLong(
     at java.lang.Long.parseLong(
     at com.cannontech.db.ExcelFileDigester.extractColumnData(
     at com.cannontech.db.ExcelFileDigester.readExcelSheet(
     at com.cannontech.db.ExcelFileDigester.main(
Code Snippet:
          //Getting ready to grab Board serial number.
          LabelCell boardSerialLabel = sheet.findLabelCell("Board Serial #");
          Long[] convertBoardSerialNumber = null;
          Cell[] boardSerialNumColumn = null;
          if(boardSerialLabel != null) {
               int columnBoardSerial = sheet.findLabelCell("Board Serial #").getColumn();
                boardSerialNumColumn = sheet.getColumn(columnBoardSerial);
               //board serial number is a long integer.
               convertBoardSerialNumber = new  Long[serialNumColumn.length];
               Cell thirdCellValue = sheet.getCell(columnBoardSerial, 0);

               //Avoiding the first cell value.
               if(boardSerialLabel.equals(thirdCellValue)) {
                    for(int i =0; i < boardSerialNumColumn.length; i++) {
                         String bSerialNumber = boardSerialNumColumn.getContents().trim();
                         if(!boardSerialNumColumn[i].equals(boardSerialLabel)) {
                              Long number = Long.parseLong(bSerialNumber);
                              convertBoardSerialNumber[i] = number;
Thank You,