请教一Excel数据导入到数据库中去!
各位高手,小弟我想做个Excel数据导入到oracle数据库中,我用的是jxl开源包,怎么老是报Exception in thread "main" java.io.FileNotFoundException: F:\phone.xls (系统找不到指定的文件。),我知道是文件路径不对,但我不知怎么去做,先谢谢啦!
public class ExcelInfo {
public static void main(String[] args) throws Exception {
ExcelInfo in = new ExcelInfo();
in.insert("F:/phone.xls","td_shop_selectphone");
}
/**
*
* @param path
* 要解析的excel文件路径
* @param dataTable
* 要写入到数据库中的表名
* @throws BiffException
* @throws IOException
*/
public void insert(String path,String dataTable) throws BiffException, IOException {
DAO dao = DAO.getDAO(Constant.DATABASE_SHOP);
File file = new File(path);
// 创建新的Excel 工作簿
Workbook rwb = null;
rwb = Workbook.getWorkbook(file);
// 得到工作簿中的第一个表索引即为excel下的sheet1,sheet2,sheet3...
Sheet sheet = rwb.getSheets()[0];
int rsColumns = sheet.getColumns();// 列数
int rsRows = sheet.getRows();// 行数
String simNumber = "" ;//每个单元格中的数据
// DBUtils jdbc=new DBUtils();
String str="";//拼接要插入的列
for (int j = 0; j <rsColumns; j++) {
Cell cell = sheet.getCell(j, 0);
simNumber = cell.getContents();
if(j==rsColumns-1){
str += simNumber ;
}else{
str += simNumber+",";
}
}
for (int i = 1; i < rsRows; i++) {
String sql = "insert into "+dataTable+"("+str+") values(";//拼接sql
System.out.println(str);
for (int j = 0; j < rsColumns; j++) {
Cell cell = sheet.getCell(j, i);
simNumber = cell.getContents();
if(j==rsColumns-1){
sql += "'"+ simNumber+"'" ;
}else{
sql +="'"+ simNumber+"',";
}
}
sql += " )";
dao.execute(sql);
}
}
}