insert excel value in to oracle data base

insert excel value in to oracle data base

Hi All I am using this code for saving excel value to oracle database table. code is working properly but in table i am geting some diffrent type value like... o org.apache.poi.hssf.usermodel.HSSFCell@19360e2

i am not getting right value...

my code is...

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 Insert { 

ConnectionToCustomDatabase dba=new ConnectionToCustomDatabase();

public static void main( String [] args ) { 
        String fileName="c:/hhh.xls"; 
        Vector dataHolder=read(fileName); 
        saveToDatabase(dataHolder);    } 
    public static Vector read(String fileName) 
       {        Vector cellVectorHolder = new Vector(); 
       try{ 
           System.out.println("try is executing");
           FileInputStream myInput = new FileInputStream(fileName); 
           System.out.println("try is executing1");
           POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput); 
           System.out.println("try is executing2");
           HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem); 
           System.out.println("try is executing3");
           HSSFSheet mySheet = myWorkBook.getSheetAt(0); 
           System.out.println("try is executing4");
           Iterator rowIter = mySheet.rowIterator(); 
           while(rowIter.hasNext()){ 
               HSSFRow myRow = (HSSFRow) rowIter.next(); 
               Iterator cellIter = myRow.cellIterator(); 
               Vector cellStoreVector=new Vector(); 
               System.out.println("try is executing5");
               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) { 
                         System.out.println("try is executing6"); 
                    String username=""; 
                     String password=""; 
                     for (int i=0;i<dataHolder.size(); i++){ 
                         Vector cellStoreVector=(Vector)dataHolder.elementAt(i); 
                         for (int j=0; j &lt; cellStoreVector.size();j++){ 
                             HSSFCell myCell = (HSSFCell)cellStoreVector.elementAt(j);
                             String st = myCell.toString(); 
                             username=st.substring(0,1); 
                             password=st.substring(0); 
                             } 
                         try{ 
                             System.out.println("try is executing7");
                             ConnectionToCustomDatabase dba;
                             Connection con = null;
                             PreparedStatement pstmt = null;
                             ResultSet rs = null;
                             //String sqlquery ="";
                             dba = new ConnectionToCustomDatabase();
                             con = dba.getVIS2Connection();

PreparedStatement stat=con.prepareStatement("insert into login(username,password1) values('"+username+"','"+password+"')");       

                         System.out.println(username);
                         System.out.println(password);
                         stat.execute();   
                                                     pstmt = con.prepareStatement(qry);
                            rs = pstmt.executeQuery();
                         System.out.println("try is executing8");
                         // System.out.println(k);
                         System.out.println("Data is inserted");
                         // stat.executeQuery()
                    if(rs.next())
                    {
                        String uu=rs.getString("username");
                        String pp1=rs.getString("password1");
                        System.out.println(uu);
                        System.out.println(pp1);

                    }
                          rs.close();
                         con.close();
                     }     
                     catch(Exception e)
                     {
                         System.out.print(e);
                     } 
                     }
                 }     
             }

plz find the bug on this code...and reply

View Answers

December 3, 2010 at 3:16 PM

Hi Friend,

You can read the data from the excel file using JDBC. For this you need to create dsn connection.

Follow these steps to create a dsn connection:

1) Go to the control Panel>>Administrative Tools>>Data Sources.

2)Click Add button and select Driver do Microsoft Excel driver. Click finish button

3)Add Data Source Name and click select workbook button to select the workbook whose data is to be retrieved.

4)Click ok and compile the following code:

import java.sql.*;
import java.util.*;

public class InsertIExcelValueToDatabase{
    public static void main(String[] args)throws Exception{
    ArrayList list1=new ArrayList();
    ArrayList list2=new ArrayList();
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:excel");
         Statement stmt = con.createStatement();
         ResultSet rs = stmt.executeQuery("select  name, address from [Sheet1$]");
         while (rs.next()) {
            String name = rs.getString("name");
            String address = rs.getString("address");
            list1.add(name);
            list2.add(address);
            System.out.println(name + "  "+address);
        }
         con.close();

         Class.forName("com.mysql.jdbc.Driver");
          Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
         Statement st = conn.createStatement();
         for(int i=0;i<list2.size();i++){
             String nn=list1.get(i).toString();
             String add=list2.get(i).toString();

             st.executeUpdate("insert into data1(name,address) values('"+nn+"','"+add+"')");
              System.out.println(nn+" "+add);
         }
    }
    catch(Exception e){
        System.out.println(e);
    }
       }
        }

Here excel is the data source name and Sheet1 is the excel sheet name.

Thanks


December 3, 2010 at 5:17 PM

thanks dear But If i upload this Excel file then how excel data will mapp to oracle database table. My project requrement is when somebuddy fill a excel form then all form value will save on database table..is it any solution of this problem. Thanks dear Yogesh


December 21, 2011 at 1:26 PM

hi i need to test ur code to check bugs so please send complete code









Related Tutorials/Questions & Answers:
insert excel value in to oracle data base
insert excel value in to oracle data base  Hi All I am using this code for saving excel value to oracle database table. code is working properly... then how excel data will mapp to oracle database table. My project requrement
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
how to read data from excel file through browse and insert into oracle database using jsp or oracle???  sir.. i have number of excel sheets which...://www.roseindia.net/answers/viewqa/JSP-Servlet/28123-write-excel-file-into-the-oracle
Advertisements
connection of java file to excel file and put data from excel file into oracle db
as wellas to oracle db to insert excel data into database...connection of java file to excel file and put data from excel file into oracle db  how to create button on excel sheet using java swing and how we
Convert the excel sheet data into oracle table through java or jsp
Convert the excel sheet data into oracle table through java or jsp  Hi Friends, Let me help this issue i am phasing Convert the excel sheet data into oracle table through java or jsp
Uploading Excel sheet record in JSP to insert data in MySql
Uploading Excel sheet record in JSP to insert data in MySql  Need Help how to upload Excel (.xls) file and insert data in Mysql using JSP it wil be wonder for me if any help me
using ajax i want to insert data into oracle database
using ajax i want to insert data into oracle database  i would like to insert/update/select/delete from jsp to oracle database using ajax? please send a code for this iam using oracl database thank you
Read data from Excel and insert in to DB and export data from DB to Excel
Read data from Excel and insert in to DB and export data from DB to Excel  Read data from Excel and insert in to DB and export data from DB to Excel Hi, I need to read the data from excel and I need to insert the same in to DB
java script unable to connect to oracle database and insert data
is to insert data from jsp to oracle database 8, so i create a table in oracle...java script unable to connect to oracle database and insert data  ... jsp coding in rose india for sql and i changed the drivers for oracle.. when i try
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
Insert excel file data into database Using Java Programming
Insert excel file data into database in Java Program In this PHP tutorial section, you will learn how to insert excel file data into the database. We have used Jakarta POI api for inserting excel file data into database in this purpose
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data into oracle database using jsp  iam a fresher newbie to softparsing i... procedure for inserting data into oracle database as bind variable and same
Insert data in Excel File from Database using JSP
Insert data in Excel File from Database  using JSP ... will retrieve the data from database, create an excel file and data insert... excel file and insert the data into excel file.ADS_TO_REPLACE_2 <
How to read every cell of an excel sheet using Apache POI and insert those data into a DB?
How to read every cell of an excel sheet using Apache POI and insert those data into a DB?   i have an excel sheet, whose data in each cell has to be read and those data has to be inserted in the DB. This has to happen for all
getting int values from form and insert it in data base in jsp
getting int values from form and insert it in data base in jsp  how... = Integer.parseInt(s); Then you can write JDBC code to insert data...=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am facing the problem while fetching the database value on jsp page while using... me what should i do for fetch the database value and shown on jsp page
Struts2 and Hibernate Fetch Data Base Value
Struts2 and Hibernate Fetch Data Base Value  Hello Sir, I am facing the problem while fetching the database value on jsp page while using... me what should i do for fetch the database value and shown on jsp page
how to insert the bulk data into the data base from the table of jsp page to another jsp page
how to insert the bulk data into the data base from the table of jsp page... to insert the marks details into the data base i have retrive the rollno and name and i have to insert the mark for n number student in the table i don't how
how insert data from databse in array and compare new data to already stored value in array
how insert data from databse in array and compare new data to already stored value in array   hello all i tried to fetch data from databse and try to stored it in an array and i want to compare new value that come from database
Oracle Database - Insert System Time
Oracle Database - Insert System Time  Hi I want to insert only system time dynamically using a statement but not a prepared statement into Oracle Database please suggest me any code
write excel file into the oracle database
write excel file into the oracle database  dear sir, i need the jsp code that reads the excel file and stores it into the oracle database table..and also i need the code to connect oracle database? thank u in advance
insert excel sheet into mysql as a table
insert excel sheet into mysql as a table  sir, i want to import an excel sheet into mysql5.0 database as in the table format using tomcat 6.0 by jsp
oracle insert statement error - JDBC
oracle insert statement error  hi.. please help me to insert a image into oracle 11g database and please say me how can i insert image from directory like G:\imagefolder\ultrasoundimage\02us02.jpeg please help me
How to insert rows from Excel spreadsheet into database by browsing the excel file?
How to insert rows from Excel spreadsheet into database by browsing the excel file?  I want to insert rows from excel sheet to database.for this i... excel file and insert rows into MSSQL database in JSP???   Have a look
insert data
insert data  i've got a problem to insert my data to database.i can...; value="<%=dateFormat.format(date)%>"> </tr> <...;input type="submit" name="Submit" value="Submit">
jsp with excel sheet data uploading into database
jsp with excel sheet data uploading into database  how to upload data in excel sheet with jsp into oracle 10g database
how to insert excel file into mysql datbase in servlet
how to insert excel file into mysql datbase in servlet  emphashow to insert excel file into mysql datbase inservletized text
oracle data backup
oracle data backup  how to take oracle tables data backup and use in another system
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.  <html> <...="Submit" value="Submit"></td> </tr> </table>
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
insert values from excel file into database
insert values from excel file into database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel... the following link: Insert values from excel file to database
single query to insert the data
single query to insert the data  How to insert data for all HTML fields in single MYSQL query
insert rows from Excel sheet into a database by browsing the file
insert rows from Excel sheet into a database by browsing the file  hello, I am trying to insert rows from Excel sheet into SQL database by browsing Excel file in java(JSP). I can insert rows using ODBC connetion. But using odbc
Export html data to excel
Export html data to excel  I am trying to export data from an html page to an excel sheet.Any advise
insert and delete data in database
insert and delete data in database  insert and delete data in database from servlets through JDBC   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 Insert Data Delete Data ThanksADS_TO_REPLACE_2
Insert Image into Excel Sheet
Insert Image into Excel Sheet In this section, you will learn how to insert image into excel sheet using Apache POI. In the given below example, am image is insert into excel sheet at row 1 and at column 1. you can specify the top
Inserting data in Excel File - Java Beginners
Inserting data in Excel File  Dear Sir, How can we fill the excel with fetched data from the database like Oracle, DB2? Is it possible to create an excel with filled data? Kindly give me the solutions to questions
insert user session into other oracle database table
insert user session into other oracle database table   hello i am a doing my project in jsp-servlet. i have doubt that when a user login to his... table. with user id i also want to insert date and current time in to database
oracle data science
oracle data science  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: oracle data science... the topic "oracle data science". Also tell me which is the good training
oracle data scientist
oracle data scientist  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: oracle data... the topic "oracle data scientist". Also tell me which is the good
oracle data science cloud
oracle data science cloud  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: oracle data... learn the topic "oracle data science cloud". Also tell me which
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
How to insert clob data??
How to insert clob data??  Can any one tell me in details how... pl/sql blocks and statements.I want to insert value of a textarea into clob... to insert more than 4000 characters.I have heard that clob fields can hold 4 gb
how to insert value in dynamic table
how to insert value in dynamic table  i am creating a project...=con.prepareStatement("insert into "+company+year+"(firstname,lastname,email... student table. and company and year value i'm getting through company table.but apache
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
ModuleNotFoundError: No module named 'django-excel-base'
ModuleNotFoundError: No module named 'django-excel-base'  Hi, My... named 'django-excel-base' How to remove the ModuleNotFoundError: No module named 'django-excel-base' error? Thanks   Hi, In your
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
save data in excel
save data in excel  hello sir, i'm new to this field i want to know can i save data in excel by html forms input,means if any one fill up form online then it is save offline in excel how can i do it can you give me solution sir
insert data into database
insert data into database  hi,thanks for reply just i am doing student information project,frontend is jsp-servlet and backend is msaccess2007. i... the data into the jsp page that data stored into the database.Here the error

Ads