-
Incompatible type for declaration. Can't convert int to java.sql.ResultSet.
I'm running an sql statement and using the ResultSet class in java, but I am having the following error message:
Incompatible type for declaration. Can't convert int to java.sql.ResultSet.
ResultSet rs=stmt.executeUpdate(sql);
I understand that executeUpdate does not return a resultset, it does return an int, but how can I modify my code to get it to work?
My code is as follows:
String sql = "SELECT patient.patientName, patientClaim.claimNo, claim.claimNo, claim.submittedDate,"+
"claim.totalCost, claim.SOB_ID, claim.visitID, claimStatus.statusID, status.StatusName,"+
"employee.employeeID, SOB.claimType FROM SOB INNER JOIN (status INNER JOIN "+
"((employee INNER JOIN ((claim INNER JOIN (patient INNER JOIN patientClaim ON"+
"patient.patientID = patientClaim.patientID) ON claim.claimNo = patientClaim.claimNo)"+
"INNER JOIN employeeClaim ON claim.claimNo = employeeClaim.claimNo) ON employee.employeeID"+
"= employeeClaim.employeeID) INNER JOIN claimStatus ON (patientClaim.claimNo = claimStatus.claimNo) AND (claim.claimNo" +
"= claimStatus.claimNo)) ON status.statusID = claimStatus.statusID) ON SOB.SOB_ID = claim.SOB_ID"+
"WHERE (((status.StatusName)='Pending') AND ((employee.employeeID)="request.getParameter("userID"));";
Statement stmt =con.createStatement();
ResultSet rs=stmt.executeUpdate(sql);
-
Very easy Maria, as executeUpdate dosent returns a ResultSet but an int you should something like this:
int returnCode = stmt.executeUpdate(sql);
Answer provided by http://www.consultoriajava.com
-
The reason why I am not using an integer is because I cannot invoke a method on an int.
lower down in the code, I need to loop through the ResultSet and display the results such as while
rs.next(). If I declare rs of type int, I cannot loop through.
-
If you want to launch a query you should use the method executeQuery() instead of executeUpdate()
Answer provided by http://www.consultoriajava.com
-
It's amazing, I used executeQuery( ) before and I still had the same error message. Now I am using it again and it seems to be working!
However, I am getting another error message when I loop through the ResultSet. The code goes as follows:
<%
while (rs.next())
out.println("<tr> <td>"+rs.getInt("claimNo") +"</td>");
out.println("<td>"+rs.getDate("submittedDate") +"</td>");
out.println("<td>"+rs.getInt("totalCost") +"</td>");
out.println("<td>"+rs.getDate("dateOfSymptoms") +"</td>");
out.println("<td>"+rs.getString("statusName") +"</td>");
out.print("<td>"+rs.getString("patientName")+ "</td></tr>");
%>
The error message is:
"[ODBC Driver Manager] Invalid cursor state"
-
Your code seems to be ok (not great but should work).
It would be of help to see your previous code, the error you are receiving is usual when you try to do
rs.getString("...");
when you havent done yet
rs.next()
Answer provided by experts at http://www.consultoriajava.com
Similar Threads
-
By swapnil_paranja in forum C++
Replies: 3
Last Post: 06-30-2005, 06:55 AM
-
By Lily in forum Database
Replies: 1
Last Post: 06-10-2002, 11:10 AM
-
Replies: 6
Last Post: 04-10-2002, 05:22 AM
-
Replies: 1
Last Post: 07-04-2001, 05:18 AM
-
By Tahui in forum VB Classic
Replies: 2
Last Post: 11-22-2000, 10:24 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks