Reading Excel data through java servlets

I am doing a project in jsp and servlet. During the project i have to read some excel data from the excel sheet and store them to DB2 database. While reading from the data from the excel sheet a problem occurred. I have used the poi package to read the data from the excel sheet and the code is correct and it reads the excel sheet. Now i just displayed the number of rows and cells in the excel sheet and while displaying the value of the every cell, the servlet displays only the address of each cell instead of displaying the value. Here i am attaching the code that i have used and the output of the servlet.
One more thing that i have noticed here is i just wrote a simple java program to read the excel data using the same steps that used earlier in the servlet. In this case the program displays the actual value of the excel cell.
Could you please help me to solve the problem.
try
String fileName = req.getParameter("file1");
String filePath = "C:
Program Files
Apache Software Foundation
Tomcat6.0
webapps
kbsearch
WEB-INF
Excel Fles
"+fileName;
poifs = new POIFSFileSystem(new FileInputStream(filePath));
book = new HSSFWorkbook(poifs);
sheet = book.getSheetAt(0);
int totalRow = sheet.getLastRowNum();
out.print("Total Number of Rows: "+totalRow);
for(int i=2; i<=totalRow; i++)
row = sheet.getRow(i);
int totalColumn = row.getLastCellNum();
out.print("<br>Total Cell: "+totalColumn);
for(int j=0; j<=totalColumn; j++)
cell = row.getCell((short)j);
out.print("<br>Cell Value: "+cell);
catch(Exception e)
out.println("
Error: "+e.getMessage());
OUTPUT
Total Number of Rows: 9
Total Cell: 9
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@1450f1f
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@e3f02a
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@ac622a
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@160c21a
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@1677737
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@1c3dc66
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@1babddb
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@1069693
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@187b360
Cell Value: org.apache.poi.hssf.usermodel.HSSFCell@1172c5

My copy of POI came with documentation including the Javadocs part:
org.apache.poi.hssf.usermodel.HSSFCell
double getNumericCellValue()
    get the value of the cell as a number. For strings we throw an exception. For blank cells we return a 0.
public java.lang.String getStringCellValue()
get the value of the cell as a string - for numeric cells we throw an exception.
For blank cells we return an empty string.
For formulaCells that are not string Formulas, we return empty String
*/

Similar Messages

  • Getting Sql Exception while using JDBC/ODBC to Excel 2007 through Java

    Iam getting the SQLexception by trying to connect using JDBC/ODBC to Excel 2007 through Java. Any Guys can tell abt this problem. java.sql.SQLException: [Microsoft][ODBC Excel Driver] External table is not in the expected format.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at InteractWithExcel.main(InteractWithExcel.java:13)

    From [Google Groups|http://groups.google.co.uk/group/sybase.public.powerbuilder.general/browse_frm/thread/97fbab02a5e6d45b]
    To use Excel as a datasource, you need to defined a named range in the spreadsheet, with the first row containing the column names.

  • Return data from Java servlet in form of JSON encoded parameters in Javascr

    How to return data from Java servlet in form of JSON encoded parameters in Javascript handler function call?
    The same is implemented in php as the following
    echo "sT.handleAjaxResponse(";
    echo json_encode($response);
    echo ");";
    How to do the same in Java servlet?
    Thanks.

    With the rising popularity of JSON (especially with Ajax), support for it has started to appear in the Java community. I am not aware of any standardized approach yet, but expect it is likely we'll see that eventually. For now, you probably want to look at a third-party library such as the [JSON in Java Library|http://www.json.org/java/], Jettison, or [Java Tools for the JSON Format|http://jsontools.berlios.de/].

  • Reset System Date Through Java

    How to change system date through java. I need some help for developing some software in java.

    as in there is a command :-
    #include <iostream.h>
    #include <dos.h>
    int main(void)
    { struct date reset;
    setdate(&reset);
    return 0;
    how can i convert it into java language and reset System date of windows, help me.

  • Reading Excel files in Java --

    Hi,
    I am trying to read an excel file from Java. It only reads the column, but I want to print the rows, which intersect with the SQL query. The following source displays only values of a column. No problem, but I would like to see the corresponding row numbers or simply number of rows. Can anyone suggest me what to do ASAP?
    Thanks,
    Gunter
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class ExcelReadTest1{
    public static void main(String[] args){
    Connection connection = null;
    try{
    //Vector vector = new Vector();
    String myString="";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection( "jdbc dbc ata-list" );
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery( "Select caseid from [sa3$] where iSchool=2" );
    //ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
    ResultSetMetaData rsmd = rs.getMetaData();
    int numberOfColumns = rsmd.getColumnCount();
    int row_num=1;
    while ((rs !=null) && rs.next()) {
    myString += "\n Row " + row_num++ + " ";
    for (int i = 1; i <= numberOfColumns; i++)
    //myString += "\n " + rsmd.getColumnName(i);
    myString += " : " + rs.getString(i);
    System.out.println(myString);
    if (i >1)
    System.out.print(", ");
    String columnValue = rs.getString(i);
    System.out.print(" " + columnValue);
    System.out.println("");
    st.close();
    con.close();
    } catch(Exception ex) {
    System.err.print("Exception: ");
    System.err.println(ex.getMessage());

    I took your code and reworked it to access a little database I keep of students at a small private school where my wife works. The Student table has columns "studentID", "firstname", "lastname", and "gradyear".
    Running your code for the output got the following. I cut and pasted the output after it had run through the first 4 students, so you can see what it's doing.
    Row 1 : 1
    1
    Row 1 : 1 : Audrey
    , Audrey
    Row 1 : 1 : Audrey : Budington
    , Budington
    Row 1 : 1 : Audrey : Budington : 2015
    , 2015
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2
    2
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia
    , Cecilia
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo
    , DeRigo
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    , 2015
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3
    3
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena
    , Serena
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes
    , Downes
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    , 2015
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4
    4
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan
    , Dylan
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan : Gellert
    , Gellert
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan : Gellert : 2015
    , 2015
    You need to figure out the flow of the thing and your println() calls and your looping. Eventually if you straighten it out you will get something like
    Row 1 : 1 : Audrey : Budington : 2015
    Row 2 : 2 : Cecilia : DeRigo : 2015
    Row 3 : 3 : Serena : Downes : 2015
    Row 4 : 4 : Dylan : Gellert : 2015
    Row 5 : 5 : Benjamin : Miller : 2015
    Row 6 : 6 : Timothy : Bolan : 2014
    Row 7 : 7 : Javin : deMello-Folsom : 2014
    Row 8 : 8 : Elizabeth : Eppolito : 2014
    Row 9 : 9 : Harrison : Evans : 2014
    Row 10 : 10 : Emily : Fay : 2014
    *** etc***
    which is what you want, isn't it?

  • Reading Excel data, FM: ALSM_EXCEL_TO_INTERNAL_TABLE problem

    Hi all,
    I'm using function module ALSM_EXCEL_TO_INTERNAL_TABLE, to read content of MS excel file and then I'm uploading those data into SAP. I'm facing probably performance problems within this module. My Excel file has 22000 rows and my ABAP program ends with short dump: MESSAGE_TYPE_X - Control Framework : Error processing control. Error occurs in function module AC_SYSTEM_FLUSH there is an exception raised:
    method_call_error: MESSAGE ID 'CNDP' TYPE 'X' NUMBER 006 RAISING CNTL_ERROR.AC_SYSTEM_FLUSH
    Could it be that it has something to do with the performance of exchanging data between application server and front-end?
    I've noticed that FM: ALSM_EXCEL_TO_INTERNAL_TABLE is reading excel file via windows clipboard (it selects whole range of workbook then it copies to clipboard). Does anybody know something more about this technique?
    Regards, Martin

    Hi Martin,
    I went through the function module ALSM_EXCEL_TO_INTERNAL_TABLE .
    With this function it is not possible to download more than 9999 records from the excel sheet.
    This is so because :
    The return table is type ALSMEX_TABLINE
    and the fields rows and columns are numc with maximum length 4 due to which its not working.
    This is all what I could find there might be another way of doing it.
    Just let me also know if u find another way of doing it.
    Regards
    Varun

  • How to read Excel file in java

    Respected sir/madam
    I want to read the values from Excel file in Java program. How can I do that. When I searched over the net I came to know that you can treat Excel file as a Database and write the code as u write for making DB connections .
    I did that but i am getting the following error ..can anybody please help..
    This is the code what i have written
    import java.io.*;
    import java.sql.*;
    public class ReadExcelFile {
    Connection c;
    Statement stmnt;
    public void checkABA_Number()
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    c = DriverManager.getConnection("jdbc:odbc:ExcelTest","",""); // ExcelTest is the DSN name
    stmnt = c.createStatement();
    ResultSet rs = stmnt.executeQuery("select * from abadata"); // abadata is my Excel file name
    while(rs.next())
    System.out.println(rs.getString(1)+" "+rs.getString(2));
    }catch(Exception e)
    System.out.println(""+e.toString());
    finally
    try
    stmnt.close();
    c.close();
    catch( Exception e )
    System.err.println( e );
    public static void main(String[] args)
    new ReadExcelFile().checkABA_Number();
    My Excel file starts from the first row and first column and also the first row contains the names of the column.
    It give me the following error..
    java.sql.SQLException: [Microsoft][ODBC Excel Driver] The Microsoft Jet database engine could not find the object 'abadata'. Make sure the object exists and that you spell its name and the path name correctly.
    How can I deal with this.?I have properly selected the worksheet while giving the DSN . Is there any versionig problem with Excel or some drivers are in appropriate..and yes i chose Microsoft Excel Driver (.xsl) from ODBC .
    I created System DSN.
    Can anybody please help me with this ? I will be very gratefull for replies
    Thanks in advance

    here is the code to read excel file
    public void readexel(String filename)
    Connection c = null;
    Statement stmnt = null;
    try
    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
    c = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + filename);
    stmnt = c.createStatement();
    String query = "Select * from [Sheet1$]" ;
    ResultSet rs = stmnt.executeQuery( query );
    while( rs.next() )
    System.out.println( rs.getString(1) );
    catch( Exception e )
    System.err.println( e );
    }

  • Reading Archived Data Through SAP Query Report

    Dear SAP Gurus,
    My client archived their SAP data in a particular year range and all the Z reports have to modified to read these archive data. Normal ABAP reports can be modified to read the archive data without no problem.
    But there are two Z SAP query reports which should be modified the same way so it will be able to read archive data.
    What is the best method for this? Does SAP Query tool provide facility to read archive data? or do I have to append the code?
    Thank you in advance for your help
    Regards,
    Isuru Fernando

    >
    Isuru U Fernando wrote:
    > hi Manthan,
    >
    > Yes I used these FMs and read the data without any problem for normal ABAP reports.
    >
    > But SAP query report is the problem. Is it advisobale to modify the SAP query generated report source code? since it is a system generated report.
    >
    > Regards,
    > Isuru
    No, do not adapt the SAP generated report source. The reason is: every time someone re-generates the query from tx. SQ01 your changes will be lost.
    You could add the functionality Manathan gave you to add to the infoset of said query - but to be honest: in my opinion that is shooting nuclear rockets at flies. Also you run the risk that every change of the infoset (add a join/delete a join) requires adjustment of said coding you applied ... and where will you be then? Fancy repairing the same query over and over again? Try talk sense to your client - go for a Z-report here ...

  • I am using NI PXIe-1073 with Labview-2014.After deploying the VI how can i read the data through host computer?

    sankar,new delhi

    PIB. I want to read the data from the GPIB after the operation complete. I am using *opc? command, which should set the status register bit after the completion of the operation, but this is not working. How to know that the Operation is complete"-Thanks.The NI-488 global status variables ibsta, ibcnt, and iberr is what you are looking for. Look into the 4882 help file for details. Also NI-Spy, http://www.ni.com/support/gpib/nispy.htm, is a good debug util. There is a website that lists common GPIB error codes and solutions. You may check there for some things to try. You'll find the link at ni.com > Support > Troubleshooting > Installation/Getting Started > GPIB, titled "GPIB Error Codes and Common Solutions".
    You could find a driver for this instrument at http://www.ni.com/devzone/idnet/default.htm . If it's not listed there, it leaves you with one of a couple options. First, I would like you to submit a request for this driver at: http://zone.ni.com/idnet97.nsf/instrumentdriverrequest/
    We develop dri
    vers based on demand and popularity so the more requests we have for it, the greater the possibility that we will develop one.
    If you would like to try developing your own instrument driver (or modify the existing one), we have documentation, model instrument drivers, and driver templates to help at :
    http://www.ni.com/devzone/idnet/development.htm
    We also have a syndicate of third party vendors that specialize in National Instruments' products and services. Some of the vendors specialize in driver development. I would suggest contacting one of the Alliance members at:
    http://www.ni.com/alliance
    Hope this helps.

  • How to read a Excel file through java coding

    Hi,
    *I need to have a code with reads data from excel file. Could u forward the jar files needed for that also.
    *presently we are using client systems so we are not able to get the following jar files. Please sent these jar files inorder to proceed me to write module processor or for writing java proxies.
    • aii_af_cci.jar
    • aii_af_mp.jar
    • aii_af_ms_api.jar
    • aii_af_ms_spi.jar
    • aii_af_trace.jar
    • aii_af_svc.jar
    • aii_af_cpa.jar
    Thank u

    Hi Shaker thank u ,
    but plz forward the jar file needed to read that is "jxl.jar" and the other jar files defined in earlier  message, to my mail id .
    just for confiramtion i defined again here:
    • aii_af_cci.jar
    • aii_af_mp.jar
    • aii_af_ms_api.jar
    • aii_af_ms_spi.jar
    • aii_af_trace.jar
    • aii_af_svc.jar
    • aii_af_cpa.jar
    jxl.jar
    Thank u

  • Newbie: Read XML data in Java

    Hello
    I am very new to Java and XML and I have some basic questions.
    I am creating some mailing lists in an XML tag where I have a identifier tag and then the e-mails as child tags. Something like this:
    <mail-list id="1" name="friends">
    <to-list id=1>
    <receiver id="1" address="[email protected]"/>
    <receiver id="2" address="[email protected]"/>
    </tolist>
    </mail-list>
    I would like to create a method that receives the name of the mail list (ex:friends) and returns all the e-mail addresses that it contains.
    How can I import data from a DOM to Java and return the text from a specific element or attribute?
    Thanks

    I would like to create a method that receives the name of the mail list (ex:friends) and returns all the e-mail addresses that it contains.You will need to traverse DOM document structure based on the filter //mail-list[@name="friends"] and then obtain each receiver id through nodelist object.
    How can I import data from a DOM to Java and return the text from a specific element or attribute?http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/TOC.html : This link has it all + contains examples to explain concepts.

  • Cannot read Excel file through ADODB in SCCM 2012 R2 WinPE

    Hi,
    I'm trying to read an excel file from WinPE 5, and get this error :"Provider cannot be found. It may not be properly installed.". My code is (Vbscript, in a HTA) :
    Dim cn
    Set cn = CreateObject("ADODB.Connection")
    With cn
      .Provider = "Microsoft.Jet.OLEDB.4.0"
      .ConnectionString = "Data Source=" & Fic_ref_deploy & ";Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;"
      .Open
    End With
    I've included many packages from SCCM  : WinPE-DismCmdlets ; WinPE-Dot3Svc ; WinPE-HTA ; WinPE-MDAC ; WinPE-NetFx ; WinPE-PowerShell.
    Have I missed something ? May I add something else ?
    Thanks,
    Fabrice

    Hello Fabrice,
    According to this
    link, for issues regarding Native data access components (ADO, Sql Native Client, MDAC, ODBC, OLEDB, JDBC, Sql Server Soap/Http), it is suggested to post to:
    http://social.technet.microsoft.com/Forums/sqlserver/en-US/home?forum=sqldataaccess
    The current forum is used for Data platform development using ADO.NET managed providers, especially System.Data.SqlClient, System.Data.Odbc and System.Data.Oledb.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Communicate with ICF services through java(servlet)

    hello,
    i'm trying to interrogate an ICF webservice through jsp , but it doesn't work .
    i can't interrogate the webservice through ajax (xml httprequest) since it's a not a cross-domain object.
    so i'm pushed to use a servlet as proxy to retreive de xml result from the ICF webservice .
    is there some kinda restriction when you call the icf webservice from a serverside language ..?
    or a special API ?
    looking forward to receiving help

    - When we are logging in to Oracle cloud on browser and execute the Oracle cloud RESTful service in another tab of same browser, we are able to get the result. But when executed the same RESTful service from a different browser or java program we get internal server error.
    - After investigation, we found that when user logs in to oracle database cloud, a cookie is set in browser with name s “OAMAuthnCookie_cstest-domo.db.us1.oraclecloudapps.com:443” and value as some random token. This cookie is passed in the subsequent requests to the RESTful Service calls when using same browser and as a result, we are able to get the results
    - In the Java program, we copied the same cookie with random token in the HTTP Request header and we got the proper response from REST APIs.
    - It seems that this cookie is created by an Oracle Middleware tool/server called as OAM – Oracle Accounts Manager, which sends the authentication token after successful authentication and creates the cookie.
    - We found that the cookie that OAM creates on authentication is exactly in the same format i.e. ‘OAMAuthnCookie_cstest-domo.db.us1.oraclecloudapps.com:443’. So, we are guessing that Oracle cloud uses OAM for authentication. Please refer to following link for same : http://docs.oracle.com/cd/E14571_01/doc.1111/e15478/sso.htm
    Can anyone please suggest:
    1.     How to provide authentication to Oracle Cloud REST APIs from java program?
    2.     How to pass the username and password in Java code to OAM (or how to communicate with OAM using Java) so that we can receive the unique token from OAM. We can use the token in the further requests? 3.     Also in Oracle cloud white papers , it is mentioned that they support OAuth2.0. But we didn’t find any URLs for same. Can anyone please confirm?
    Thanks
    ~ Neeraj Girolkar

  • How to Lock Excel Sheet through Java Code

    Hi
    Iam using Jasper Reports.Iam exporting to Excel.I want to Lock Excel sheet after Export.I need code how to lock and unlock
    TQ

    I guess you need some library that can modify Excel files, like JExcel or Jakarta POI.

  • Reading Excel from Java

    Hello,
    I would want to read excel data from Java. I do not want to register any excel drivers as I will not be able to know the file to be read before hand. Are there any better ways to solve this ?
    Thanks in Advance,
    Prasanna

    hi prasanna
    if you are using jdbc-odbc bridge I would recommend you to test the
    program with excel files with varying sizes like 3,5, 12, 20 etc. There
    is a some problem with the driver that it chops off some data.
    For example if you have 20k excel file the driver may read in 9k chunks so you get 18k of data read and the driver ignores rest 2k.
    Make sure of that it works on all sizes of input data.
    bib/-

Maybe you are looking for

  • Error message when launching updated iTunes

    After updating to iTunes 11, I've been unable to launch iTunes on my computer. (I'm using Windows 7 Home) When I try to open iTunes, I'm shown an error message that looks like this: Any idea what could be wrong? I've tried uninstalling iTunes and all

  • DVD drive not recognized after Security update

    Hello - Well, for whatever reason I decided to apply some Apple software updates today. I repaired permissions, did a back up to an external Firewire drive with SuperDuper and downloaded several packages - iDVD 6.0.2, iMovie 6.0.2, Quicktime 7.1, iPh

  • Trouble compiling Intel 2.9.1 driver

    Hello. I have an HP G62 laptop with onboard intel graphics. After I installed Arch I had a problem. Enabling KMS would make my screen go black on boot (and stay black). Not enabling KMS would make X refuse to start since the new Intel drivers require

  • Unexpected Quits in multiple applications at Save or Import/Export window

    Hello, For several months I have Apple and Adobe applications as well as Firefox, randomly quit when bringing up the Save, or Import/Export window. (I have copies of the error logs.) I thought I had it fixed since I haven't had any issues for some ti

  • How can I establish connection between DirectSoft Programming software and LookOut

    Hi,         I am working with a DL06 PLC. I am trying to a develop a LookOut Direct HMI for this tainer. I would like to know if there is any option in LookOut where it allows me to run small parts of PLC code along with HMI so that i can toggle disc