Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading Excel File from a POJO

 
Pooja Dornadhula
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

------------------------------CODE----------------------------------------

public Object populateData(File file){
Connection conn = null;
PreparedStatement dataQueryPS = null;
ResultSet dataQueryRS = null;
try{
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){
e.printStackTrace();
return null;
}finally{
try{
System.out.println(" Iam in final try");

dataQueryRS.close();
dataQueryPS.close();
conn.close();
}catch(Exception t){

}
}
}

------------------------------CODE----------------------------------------

Regards
Pooja D
 
Joe Ess
Bartender
Pie
Posts: 9258
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
krishnamoorthy kitcha
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rgs
k.krishnamoorthy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic