wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes Reading Excel File from a POJO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading Excel File from a POJO" Watch "Reading Excel File from a POJO" New topic

Reading Excel File from a POJO

Pooja Dornadhula

Joined: Aug 07, 2007
Posts: 8
I am using the below code to read the Excel file. But i am not able to come out of the for loop of result set. Please help me in this issue.


public Object populateData(File file){
Connection conn = null;
PreparedStatement dataQueryPS = null;
ResultSet dataQueryRS = null;
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
conn = DriverManager.getConnection("jdbc dbc river={Microsoft Excel Driver (*.xls)};DBQ=" + file);
String dataQuery = "Select REFNO,DDNO,URL,DATE from [Sheet1$] where REFNO <> null";
dataQueryPS = conn.prepareStatement(dataQuery);
dataQueryRS = dataQueryPS.executeQuery();
for(int i = 0 ;dataQueryRS.next();i++){
System.out.println("i :::: "+i +" "+dataQueryRS.getString(1));
return null;
catch(Exception e){
return null;
System.out.println(" Iam in final try");

}catch(Exception t){



Pooja D

SCJP 1.4, SCWCD 1.4
Joe Ess

Joined: Oct 29, 2001
Posts: 8836

As I said in your previous post, some Excel spreadsheet versions have over a million rows. How many rows are you printing out?
By the way, please Use Code Tags when you post code.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
krishnamoorthy kitcha
Ranch Hand

Joined: Feb 04, 2006
Posts: 96
Hi pooja !!!

check in this line

dataQueryPS = conn.prepareStatement(dataQuery);
This is Returns the PreparedStatement not a result set

dataQueryRS = dataQueryPS.executeQuery();
Here only, returns the resultset

check and tell me your feedback
I agree. Here's the link: http://aspose.com/file-tools
subject: Reading Excel File from a POJO
Similar Threads
mysql connectivity with jboss
File as Attachment in J2ME client
Method keeps returning null
problem while reading data from excel sheet
How to send bytearray from Servlet to Midlet application?