Reading Excel file and inserting data into database in java

preview_player
Показать описание
Check My first Comment For Download Code
Рекомендации по теме
Комментарии
Автор

Code
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;

import
import

import jxl.Sheet;
import jxl.Workbook;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
*
*
*
* @author Mahesh Dubal
*
*/
public class SaveCardStock {

public static int saveCardStock(String filename)
{
int res=0;
try
{
String FilePath = "D:\\product.xls";
int i=0;
String st = null, st1 = null, st2 = null, st3=null,st4=null,st5=null,st6=null,st7=null,st8=null,st9=null,st10 = null, st11 = null, st12=null,st13=null,st14=null,st15=null,st16=null,st17=null,st18=null,st19=null,st20=null;
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);

// TO get the access to the sheet
Sheet sh = wb.getSheet("Sheet1");

// To get the number of rows present in sheet
int totalNoOfRows = sh.getRows();

// To get the number of columns present in sheet
int totalNoOfCols = sh.getColumns();
Connection
for (int row = 0; row < totalNoOfRows; row++) {

for (int col = 0; col < totalNoOfCols; col++) {
try
{
if(col==0)
{
st= sh.getCell(col, row).getContents();
}

else if(col==2)
{
st2= sh.getCell(col, row).getContents();
}
else if(col==3)
{
st3= sh.getCell(col, row).getContents();
}
else if(col==4)
{
st4= sh.getCell(col, row).getContents();
}
else if(col==5)
{
st5= sh.getCell(col, row).getContents();
}
else if(col==6)
{
st6= sh.getCell(col, row).getContents();
}
else if(col==7)
{
st7= sh.getCell(col, row).getContents();
}
else if(col==8)
{
st8= sh.getCell(col, row).getContents();
}
else if(col==9)
{
st9= sh.getCell(col, row).getContents();
}



}

catch(Exception ee)
{
ee.printStackTrace();
}
}

PreparedStatement into product(sn, maincategories, subcategories, brand, type, productname, dtp, suppliyer, remarks) values(?, ?, ?, ?, ?, ?, ?, ?, ?)");
pstmt.setString(1, st);
pstmt.setString(2, st2);
pstmt.setString(3, st3);
pstmt.setString(4, st4);
pstmt.setString(5, st5);
pstmt.setString(6, st6);
pstmt.setString(7, st7);
pstmt.setString(8, st8);
pstmt.setString(9, st9);
res=pstmt.executeUpdate();

System.out.println(res);
}
System.out.println(i);

}
catch(Exception ee)
{
ee.printStackTrace();
}
return res;

}
public static void main(String[] args) {
saveCardStock("abc");
}
}

Creative_Technology_VM
Автор

Hi! i did exactly the same, but it throws exception when use xlsx file, but works when use xlx. Do you have some tip?

beonecommercepartners
Автор

<!--This is for exporting table to excel -->

Creative_Technology_VM
Автор

I am getting error in the import statements, do i need to add some jar files or libraries???

rishabhraghuvanshi
Автор

ava.io.FileNotFoundException: Excel 97-2003 Worksheet.xls (The system cannot find the file specified)


bruh i got this error what should i do?

ndmscoi
Автор

what's that ("abc") in your code..i don't get it!

rukhsarpatwe
join shbcf.ru