aspose file tools*
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
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: No data read