guyss this is my code for convrting xls file to mysql but got some error while running
import java.util.*;
import java.lang.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Row;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
public class ImportData {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection
("jdbc:mysql://localhost/apnakhata_V1","root","abhi1402");
con.setAutoCommit(false);
PreparedStatement pstm = null ;
FileInputStream input = new FileInputStream("D:/New
Folder/apnakhata1.xls");
POIFSFileSystem fs = new POIFSFileSystem( input );
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
Row row;
for(int i=1; i<=sheet.getLastRowNum(); i++){
row = sheet.getRow(i);
System.out.println(i);
String CountryName = row.getCell(1).getStringCellValue();
String CountryCode = row.getCell(2).getStringCellValue();
String BankName = row.getCell(3).getStringCellValue();
String Website = row.getCell(4).getStringCellValue();
String Name = row.getCell(5).getStringCellValue();
String SMS = row.getCell(6).getStringCellValue();
int SMSNumber = (int) row.getCell(7).getNumericCellValue();
int CustomerCare = (int) row.getCell(8).getNumericCellValue();
String sql = "INSERT INTO bank VALUES('"+CountryName+"','"+CountryCode
+"','"+BankName+"','"+Website+"','"+Name+"','"+SMS +"','"+SMSNumber
+"','"+CustomerCare+"')";
pstm = (PreparedStatement) con.prepareStatement(sql);
pstm.execute();
System.out.println("Import rows "+i);
}
con.commit();
pstm.close();
con.close();
input.close();
System.out.println("Success import excel to mysql table");
}catch(ClassNotFoundException e){
e.printStackTrace();
System.out.println(e);
}catch(SQLException ex){
ex.printStackTrace();
System.out.println(ex);
}catch(IOException ioe){
ioe.printStackTrace();
System.out.println(ioe);
}
}
}
1
Exception in thread "main" java.lang.IllegalStateException: Cannot get a numeric value from a text cell
at org.apache.poi.hssf.usermodel.HSSFCell.typeMismatc h(HSSFCell.java:647)
at org.apache.poi.hssf.usermodel.HSSFCell.getNumericC ellValue(HSSFCell.java:672)
at ImportData.main(ImportData.java:40)
this is the error i got ......