Results 1 to 6 of 6
  1. #1
    saran123 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default 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

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    Have you tried searching for code that does that? There are examples posted here to do a lot of it.

  3. #3
    saran123 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default 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

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,252
    Rep Power
    19

  5. #5
    saran123 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default 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

  6. #6
    mrtshezi is offline Member
    Join Date
    Oct 2008
    Posts
    1
    Rep Power
    0

    Default Hello 2 everyone

    I will like 2 send a big HELLO 2 everyone in the forum. i am new in this site and i hope i will be able to help others in solving java problems and also get get from others. I am doing java in the university level. Together nothing can stand on our way

Similar Threads

  1. Need a solution to read and store data from a file
    By sheetalnri in forum New To Java
    Replies: 10
    Last Post: 09-30-2010, 06:43 AM
  2. How to create folder(s) and store data?
    By Grom in forum New To Java
    Replies: 2
    Last Post: 08-20-2008, 09:01 AM
  3. Replies: 5
    Last Post: 07-30-2008, 09:30 AM
  4. Save data from Excel sheet to servlet
    By chandu.v in forum Java Servlet
    Replies: 2
    Last Post: 04-10-2008, 01:51 PM
  5. how to use btree to store data
    By fred in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •