write spreadsheet

Ads
 

write spreadsheet

what is the java code to write a spreadsheet to database

View Answers

May 4, 2012 at 11:44 AM

  import java.io.*;
  import java.sql.*;
  import java.util.*;
  import java.util.regex.*;
  import org.apache.poi.hssf.usermodel.*;
  import org.apache.poi.poifs.filesystem.POIFSFileSystem;

  public class InsertExcelFileData {
  public static void main( String [] args ) {
    String fileName="c:/data.xls";
    Vector dataHolder=read(fileName);
    saveToDatabase(dataHolder);
}
    public static Vector read(String fileName)    {
    Vector cellVectorHolder = new Vector();
    try{
            FileInputStream myInput = new FileInputStream(fileName);
            POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
        HSSFSheet mySheet = myWorkBook.getSheetAt(0);
       Iterator rowIter = mySheet.rowIterator(); 
       while(rowIter.hasNext()){
              HSSFRow myRow = (HSSFRow) rowIter.next();
              Iterator cellIter = myRow.cellIterator();
              Vector cellStoreVector=new Vector();
              while(cellIter.hasNext()){
                      HSSFCell myCell = (HSSFCell) cellIter.next();
                      cellStoreVector.addElement(myCell);
              }
              cellVectorHolder.addElement(cellStoreVector);
      }
    }catch (Exception e){e.printStackTrace(); }
    return cellVectorHolder;
}
    private static void saveToDatabase(Vector dataHolder) {
    String name="";
            String address="";
            for (int i=0;i<dataHolder.size(); i++){
               Vector cellStoreVector=(Vector)dataHolder.elementAt(i);
                    for (int j=0; j < cellStoreVector.size();j++){
                            HSSFCell myCell = (HSSFCell)cellStoreVector.elementAt(j);
                            String st = myCell.toString();
                             name=st.substring(0,1);
                             address=st.substring(0);
                                                    }
                    try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
    Statement stat=con.createStatement();
    int k=stat.executeUpdate("insert into data(name,address) value('"+name+"','"+address+"')");
    System.out.println("Data is inserted");
    stat.close();
    con.close();
    }
    catch(Exception e){}
    }
    }
  }

In the above code we have defined a file data.xls. This file contains two columns Name and Address.

Ads









Related Tutorials/Questions & Answers:
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
write spreadsheet
write spreadsheet  what is the java code to write a spreadsheet to database
Advertisements
ModuleNotFoundError: No module named 'spreadsheet'
ModuleNotFoundError: No module named 'spreadsheet'  Hi, My Python... 'spreadsheet' How to remove the ModuleNotFoundError: No module named 'spreadsheet' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'spreadsheet'
ModuleNotFoundError: No module named 'spreadsheet'  Hi, My Python... 'spreadsheet' How to remove the ModuleNotFoundError: No module named 'spreadsheet' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'bluesky-spreadsheet'
ModuleNotFoundError: No module named 'bluesky-spreadsheet'  Hi, My... named 'bluesky-spreadsheet' How to remove the ModuleNotFoundError: No module named 'bluesky-spreadsheet' error? Thanks   Hi
ModuleNotFoundError: No module named 'google_spreadsheet'
ModuleNotFoundError: No module named 'google_spreadsheet'  Hi, My... named 'google_spreadsheet' How to remove the ModuleNotFoundError: No module named 'google_spreadsheet' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'google_spreadsheet'
ModuleNotFoundError: No module named 'google_spreadsheet'  Hi, My... named 'google_spreadsheet' How to remove the ModuleNotFoundError: No module named 'google_spreadsheet' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'google_spreadsheet'
ModuleNotFoundError: No module named 'google_spreadsheet'  Hi, My... named 'google_spreadsheet' How to remove the ModuleNotFoundError: No module named 'google_spreadsheet' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'o2-google-spreadsheet'
ModuleNotFoundError: No module named 'o2-google-spreadsheet'  Hi...: No module named 'o2-google-spreadsheet' How to remove the ModuleNotFoundError: No module named 'o2-google-spreadsheet' error? Thanks   Hi
ModuleNotFoundError: No module named 'spreadsheet-maker'
ModuleNotFoundError: No module named 'spreadsheet-maker'  Hi, My... named 'spreadsheet-maker' How to remove the ModuleNotFoundError: No module named 'spreadsheet-maker' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'Spreadsheet-HTML'
ModuleNotFoundError: No module named 'Spreadsheet-HTML'  Hi, My... named 'Spreadsheet-HTML' How to remove the ModuleNotFoundError: No module named 'Spreadsheet-HTML' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'spreadsheet-maker'
ModuleNotFoundError: No module named 'spreadsheet-maker'  Hi, My... named 'spreadsheet-maker' How to remove the ModuleNotFoundError: No module named 'spreadsheet-maker' error? Thanks   Hi, In your
Version of com.supwisdom>spreadsheet-mapper-parent dependency
List of Version of com.supwisdom>spreadsheet-mapper-parent dependency
ModuleNotFoundError: No module named 'django-spreadsheet-reports'
ModuleNotFoundError: No module named 'django-spreadsheet-reports'  Hi...: No module named 'django-spreadsheet-reports' How to remove the ModuleNotFoundError: No module named 'django-spreadsheet-reports' error? Thanks
ModuleNotFoundError: No module named 'django-spreadsheet-reports'
ModuleNotFoundError: No module named 'django-spreadsheet-reports'  Hi...: No module named 'django-spreadsheet-reports' How to remove the ModuleNotFoundError: No module named 'django-spreadsheet-reports' error? Thanks
ModuleNotFoundError: No module named 'django-spreadsheet-reports'
ModuleNotFoundError: No module named 'django-spreadsheet-reports'  Hi...: No module named 'django-spreadsheet-reports' How to remove the ModuleNotFoundError: No module named 'django-spreadsheet-reports' error? Thanks
ModuleNotFoundError: No module named 'domdf-spreadsheet-tools'
ModuleNotFoundError: No module named 'domdf-spreadsheet-tools'  Hi...: No module named 'domdf-spreadsheet-tools' How to remove the ModuleNotFoundError: No module named 'domdf-spreadsheet-tools' error? Thanks   
ModuleNotFoundError: No module named 'domdf-spreadsheet-tools'
ModuleNotFoundError: No module named 'domdf-spreadsheet-tools'  Hi...: No module named 'domdf-spreadsheet-tools' How to remove the ModuleNotFoundError: No module named 'domdf-spreadsheet-tools' error? Thanks   
ModuleNotFoundError: No module named 'google-spreadsheet-py'
ModuleNotFoundError: No module named 'google-spreadsheet-py'  Hi...: No module named 'google-spreadsheet-py' How to remove the ModuleNotFoundError: No module named 'google-spreadsheet-py' error? Thanks   Hi
ModuleNotFoundError: No module named 'google-spreadsheet-py'
ModuleNotFoundError: No module named 'google-spreadsheet-py'  Hi...: No module named 'google-spreadsheet-py' How to remove the ModuleNotFoundError: No module named 'google-spreadsheet-py' error? Thanks   Hi
ModuleNotFoundError: No module named 'google-spreadsheet-py'
ModuleNotFoundError: No module named 'google-spreadsheet-py'  Hi...: No module named 'google-spreadsheet-py' How to remove the ModuleNotFoundError: No module named 'google-spreadsheet-py' error? Thanks   Hi
ModuleNotFoundError: No module named 'python-barcode-spreadSheet'
ModuleNotFoundError: No module named 'python-barcode-spreadSheet'  Hi...: No module named 'python-barcode-spreadSheet' How to remove the ModuleNotFoundError: No module named 'python-barcode-spreadSheet' error? Thanks
ModuleNotFoundError: No module named 'python-google-spreadsheet'
ModuleNotFoundError: No module named 'python-google-spreadsheet'  Hi...: No module named 'python-google-spreadsheet' How to remove the ModuleNotFoundError: No module named 'python-google-spreadsheet' error? Thanks  
ModuleNotFoundError: No module named 'python-google-spreadsheet'
ModuleNotFoundError: No module named 'python-google-spreadsheet'  Hi...: No module named 'python-google-spreadsheet' How to remove the ModuleNotFoundError: No module named 'python-google-spreadsheet' error? Thanks  
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
Create SpreadSheet same as excel using java applet
Create SpreadSheet same as excel using java applet  Hi Ji, May i know to create new excel sheet using java Applet
write a program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
Maven Dependency spreadsheet-mapper-parent >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of com.supwisdom >> spreadsheet-mapper-parent version1.0.0 in your project
Maven Dependency spreadsheet-mapper-parent >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of com.supwisdom >> spreadsheet-mapper-parent version1.0.1 in your project
Maven Dependency spreadsheet-mapper-parent >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of com.supwisdom >> spreadsheet-mapper-parent version1.0.2 in your project
Maven Dependency spreadsheet-mapper-parent >> 1.0.3
You should include the dependency code given in this page to add Maven Dependency of com.supwisdom >> spreadsheet-mapper-parent version1.0.3 in your project

Ads