Results 1 to 6 of 6
- 10-02-2008, 12:56 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 5
- Rep Power
- 0
How to read data from excel and store it in db
Hi,
I wrote the code to read the data from excel and given below.Now its reading all the values and printing it in Java Console. Cold you explain me where to store the data read from excel and how can i connect it to database?If possible.I do not know how to get these data and store in database.So please provide me
public class ReadExcelTest
{
private String inputFile;
public void setInputFile(String inputFile)
{
this.inputFile = inputFile;
}
public void read() throws IOException, WriteException {
File inputWorkbook = new File(inputFile);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
Sheet sheet = w.getSheet(0);// Get the first sheet
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++)
{
for (int i = 0; i < sheet.getRows(); i++)
{
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
if (cell.getContents().isEmpty())
{
System.out.println("This column is empty ");
}
if (cell.getType() == CellType.LABEL)
{
System.out.println( "The contents of the excel are "+ cell.getContents());
}
if (cell.getType() == CellType.NUMBER)
{
System.out.println("I got a number "+ cell.getContents());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws WriteException, IOException {
ReadExcel test = new ReadExcel();
test.setInputFile("C:/xxx.xls");
test.read();
}
}
Thanks in advance
- 10-02-2008, 02:18 PM #2
Have you tried searching for code that does that? There are examples posted here to do a lot of it.
- 10-03-2008, 09:20 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 5
- Rep Power
- 0
Thanks Norm
I read some threads posted here similar to my thread but i feel my case is different.As i am new to Java, i do not know how(coding) to store the excel read data to database.Please help me to solve this. Any helpy can be appreciated as this is a high priority work for me.
Thanks
- 10-03-2008, 09:39 AM #4
- 10-03-2008, 10:07 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 5
- Rep Power
- 0
Thanks Darryl
Thanks Darryl. But i have a query.I read the data from excel and if i want to store it in database, i need jdbc connection.But i am using JExcel API, so is DSN needed for jdbc connection?Because in the code i am giving the Excel path directly.If i use DSN, which path i need to give(whether Excel file path or the Database in which i am going to store)?.So DSN is required or not?But without DSN, how can i connect my database? Please clarify my doubt.
Here i am JEXcel API and giving the Excel path in InputFile
public static void main(String[] args) throws WriteException, IOException {
ReadExcel test = new ReadExcel();
test.setInputFile("C:/xxx.xls");
test.read();
}
Thanks
- 10-03-2008, 10:19 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Need a solution to read and store data from a file
By sheetalnri in forum New To JavaReplies: 10Last Post: 09-30-2010, 06:43 AM -
How to create folder(s) and store data?
By Grom in forum New To JavaReplies: 2Last Post: 08-20-2008, 09:01 AM -
How do you read from a file, and then store the info in an array?
By szimme101 in forum New To JavaReplies: 5Last Post: 07-30-2008, 09:30 AM -
Save data from Excel sheet to servlet
By chandu.v in forum Java ServletReplies: 2Last Post: 04-10-2008, 01:51 PM -
how to use btree to store data
By fred in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks