• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CSV file validating issue

 
prashantpk kulkarni
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,

I want to import CSV file which contains Part number, Part name and Part details field,
While inserting it should not allow duplicate part number(as part number is a unique field).
Below is the code which I am using to insert the data and validate part number...

if(!firstRow)
{
//To get the data from database
List<SubAssembly> subAssembies=assemblyDao.getSubAssembyBySubAssemblyId(subAssemblyCmd.getParentId(),cellTempList.get(0).toString(),subAssemblyCmd.getParentTypeId());
//checks whether the part exists at the same level
if(subAssembies.size()==0)
{
SubAssembly objSubAssembly =new SubAssembly();
try
{
//To validate part number field
if( !validateSubAssembly(cellTempList,subAssembly ))
{
return errorReport;
}

objSubAssembly.setSubAssemblyNumber(cellTempList.get(0).toString());
objSubAssembly.setSubAssemblyName(cellTempList.get(1).toString());
if(cellTempList.get(2).toString()!="")
objSubAssembly.setSizeOrRatio(cellTempList.get(2).toString());
if(!cellTempList.get(3).toString().equals(""))
objSubAssembly.setNoOfUnits((int)(Double.parseDouble(cellTempList.get(3).toString())));
if(!cellTempList.get(4).toString().equals(""))
objSubAssembly.setSubWeight (Double.parseDouble(cellTempList.get(4).toString()) );
if(!cellTempList.get(5).toString().equals(""))
objSubAssembly.setStatus(cellTempList.get(5).toString());
if(!cellTempList.get(6).toString().equals(""))
objSubAssembly.setRemark(cellTempList.get(6).toString());
}
catch(IndexOutOfBoundsException a)
{
objSubAssembly.setRemark("");
}
catch (NumberFormatException e)
{
e.printStackTrace();
}

subAssemblyCmd.getSubAssemblyList().add(objSubAssembly);
}
else
return cellTempList.get(0).toString() +" already exists at the same level";
}
else
firstRow=false;

}
//To insert the data into database
assemblyService.addSubAssembly(subAssemblyCmd);

The data is not inserting into the database and its not validating the part number,
so please have a look into the above my code and provide me the solution to insert data and validate part number field.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic