This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
please help me out with this. how to import data from excel sheet to database in java i tried different codes but it is not working . please help me friends
strOutputXml=ejbObj.makeCall(strInputXml.toString());
xmlResponse=new DMSXmlResponse(strOutputXml);
System.out.println("Cabinet Connected Successfully\n");
System.out.println("Fetched List While Connect:\n\n"+strOutputXml);
xmlList = xmlResponse.createList("Instruments", "Instrument");
if(xmlResponse.getVal("Status").equals("0")){
strSessionId=xmlResponse.getVal("UserDBId");
System.out.println("Session ID of this connection:"+strSessionId);
}else{
System.out.println("Error in Connecting Application Server");
return;
}
}
public void DisconnectCabinet() throws Exception{
List cellDataList = new ArrayList();
try
{
/**
* Create a new instance for FileInputStream class
*/
FileInputStream fileInputStream = new FileInputStream(fileName);
/**
* Create a new instance for POIFSFileSystem class
*/
POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);
/*
* Create a new instance for HSSFWorkBook Class
*/
HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);
HSSFSheet hssfSheet = workBook.getSheetAt(0);
/**
* Iterate the rows and cells of the spreadsheet
* to get all the datas.
*/
Iterator rowIterator = hssfSheet.rowIterator();
while (rowIterator.hasNext())
{
HSSFRow hssfRow = (HSSFRow) rowIterator.next();
Iterator iterator = hssfRow.cellIterator();
List cellTempList = new ArrayList();
while (iterator.hasNext())
{
HSSFCell hssfCell = (HSSFCell) iterator.next();
cellTempList.add(hssfCell);
}
cellDataList.add(cellTempList);
}
}
catch (Exception e)
{
e.printStackTrace();
}
/**
* Call the printToConsole method to print the cell data in the
* console.
*/
printToConsole(cellDataList);
}
/**
* This method is used to print the cell data to the console.
* @param cellDataList - List of the data's in the spreadsheet.
*/
public void printToConsole(List cellDataList)
{
for (int i = 0; i < cellDataList.size(); i++)
{
List cellTempList = (List) cellDataList.get(i);
for (int j = 0; j < cellTempList.size(); j++)
{
HSSFCell hssfCell = (HSSFCell) cellTempList.get(j);
String stringCellValue = hssfCell.toString();
System.out.print(stringCellValue + "\t");
System.out.println();
try{
Statement sta = conn.createStatement();
String table = "INSERT INTO ashok (username) VALUES('" +stringCellValue+ "')";
System.out.println(table);
Session ID of this connection:1272716213
Date
Error in appending null
kumar
Error in appending null
appdata
Error in appending null
raja
Error in appending null
approver V1
Error in appending null
naveen
Error in appending null
APS V1
Error in appending null
as
Error in appending null
ce
Error in appending null
ce V1
Error in appending null
ce V1(2012_3_26_16_58_50_920)
Error in appending null
CEASCANOC20JOB
Error in appending null
Classificator
Error in appending null
Custom Reports
Error in appending null
Cabinet DisConnected Successfully and session id is:1272716213
This is my output.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
Print the full exception stack trace instead of just the error message. That way you'll know in which line of code the error occurred.