This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes java.sql.SQLException: No data read 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 » Databases » JDBC
Bookmark "java.sql.SQLException: No data read" Watch "java.sql.SQLException: No data read" New topic
Author

java.sql.SQLException: No data read

vas reddy
Greenhorn

Joined: Jun 11, 2008
Posts: 23
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

Joined: Jun 11, 2008
Posts: 23
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();
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Vas,
Thanks for sharing the solution for others who have the same problem!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
Don't get me started about those stupid light bulbs.
 
subject: java.sql.SQLException: No data read
 
Similar Threads
Problem when Retreiving from DataBase
SQLException: No data found
calling stored proc. w/ resultset return?
Couldn't retreive a String from the result set
java stored procedure problems