• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

java.sql.SQLException: No data read

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am getting "java.sql.SQLException: No data read" when I run the following code.
but when I used ResultSet rs = stmt.executeQuery(); (the commented line in the code)
I do n't get any error. Can any one please explain the reason for this?

(The query is not returning any rows from DB,
rs is not null in both the cases.
ResultSet rs = stmt.getResultSet();
or
ResultSet rs = stmt.executeQuery();
)



<CODE --- STARTS >

con = ConnectionMain.getDbConnection();
CallableStatement cstmt = con.prepareCall("{ call XXXX(?, ?, ?) }");
cstmt.setString(1, set1);
cstmt.setString(2, set2);
cstmt.registerOutParameter(3, Types.VARCHAR);
cstmt.execute();
app = cstmt.getString(3);

if (app == null || app.length()==0) {
PreparedStatement stmt = con.prepareStatement(query);
stmt.setString(1, app_num);

ResultSet rs = stmt.getResultSet();
//ResultSet rs = stmt.executeQuery();


if (rs.next()) {
app = rs.getString(1);
}
stmt.close();
rs.close();
}


<CODE --- ENDS>

thanks
 
vas reddy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the reason
execute the query before getting the resultset.

either you use

stmt.executeQuery();
ResultSet rs=stmt.getResultSet();


or

ResultSet rs = stmt.executeQuery();
 
author & internet detective
Posts: 42173
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vas,
Thanks for sharing the solution for others who have the same problem!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic