wood burning stoves 2.0*
The moose likes Servlets and the fly likes Problem with Result Set pointer. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with Result Set pointer." Watch "Problem with Result Set pointer." New topic
Author

Problem with Result Set pointer.

Thomas Knight
Ranch Hand

Joined: Feb 08, 2003
Posts: 33
I have code that just counts the number of records in my result set after I had executed a query. If the number of records is 0 I just print that nothing was found. If I have more than 0 records then I want to print the first row of the result set. I am having problem with the Result Set pointer. After I have done the count, the Result Pointer is after the last record. Before I try to print the 1st record of the Result Set, I try to move the pointer back to the first record in the Result set. When the program gets to the code that prints the data from the record set it blows up. ANy idea what I am doing wrong? I am sure it has something to do with the Result Set pointer. The code looks like this...
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
Thomas,
It would be extremely helpful in diagnosing the problem if you also included the error message that you are getting.
Mark
Thomas Knight
Ranch Hand

Joined: Feb 08, 2003
Posts: 33
Here is the error message I get ...
I didn't get this error when I did not change the position of the result set pointer, so I am pretty sure it has something to do with where the pointer currently is.
Error:500
Internal Servlet Error:
java.lang.UnsupportedOperationException
at sun.jdbc.odbc.JdbcOdbcResultSet.absolute(JdbcOdbcResultSet.java:2452)
at hw4a.doPost(hw4a.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
at com.sun.web.core.InvokerServlet.service(InvokerServlet.java:169)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:140)
at com.sun.web.core.Context.handleRequest(Context.java:375)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:135)
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
It seems the driver you are using do not support the ResultSet.absolute(int) method.
The ResultSet class is an interface. Every DB vendor implements its own ResultSet, so you may find some methods not to be supported by the JDBC classes you are using.
Check also the type of your ResultSet, if it is "TYPE_FORWARD_ONLY" you will get a SQLException.
BTW rs.absolute(1); = rs.first();
HTH
Thomas Knight
Ranch Hand

Joined: Feb 08, 2003
Posts: 33
Juanjo, thanks for the ideas. I got rid of the absolute and did the rs.first() and received the same error. Next I changed the parameters of the createStatement() method so my record set would not allow updating of the table and was scrollable but insensitive to changes. Therefore I had this originally...

then using you idea that the Result Set was forward only I changed the statement to...

After I made that change I received the same error. At this point I am baffeled, I am not sure what I am doing wrong Does anybody else have an idea?

Originally posted by Juanjo Bazan:
It seems the driver you are using do not support the ResultSet.absolute(int) method.
The ResultSet class is an interface. Every DB vendor implements its own ResultSet, so you may find some methods not to be supported by the JDBC classes you are using.
Check also the type of your ResultSet, if it is "TYPE_FORWARD_ONLY" you will get a SQLException.
BTW rs.absolute(1); = rs.first();
HTH
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
Thomas,
I was thinking the same thing that Juanjo already mentioned - the JDBC driver your are using may not support scrollable result sets. It looks like you are using the JDBC-ODBC bridge... I have never used it myself but a quick look throught the J2SE docs indicates that scrollable result sets were not supported by that driver until J2SE 1.3. What version of J2SE are you using?
Mark
Thomas Knight
Ranch Hand

Joined: Feb 08, 2003
Posts: 33
I am using J2SE 1.2.2, that might explain it. I am using the JDBC-ODBC bridge since I am using an Access DB for the backend. I am not sure on what to do now. All I need to do is to look at the Result set and see if anything is in it, If not, an error message should be printed out, if there is something I jsut want to print the fileds in teh Result set. Seems simple enough, what do you suggest I do to accomplish this? Thanks.

Originally posted by Mark Bensing:
Thomas,
I was thinking the same thing that Juanjo already mentioned - the JDBC driver your are using may not support scrollable result sets. It looks like you are using the JDBC-ODBC bridge... I have never used it myself but a quick look throught the J2SE docs indicates that scrollable result sets were not supported by that driver until J2SE 1.3. What version of J2SE are you using?
Mark
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
You dont need a scrollable result set to do what you want... just rearrange your existing code a little bit:

If there was a real need to iterate through the result set multiple times and your driver does not support scrollable result sets, you could create an inner class with members to hold all the values from a single row and store them in an ArrayList. Then you can just iterate through the ArrayList instead of the result set.
I hope this helps,
Mark
[ April 12, 2003: Message edited by: Mark Bensing ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Result Set pointer.
 
Similar Threads
Couldn't retreive a String from the result set
Getting Problem in Delete operation in Struts application
Servet and Jdbc
jsp & database
Help with JSP!!!