Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Resultset + TYPE_FORWARD_ONLY problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Resultset + TYPE_FORWARD_ONLY problem " Watch "Resultset + TYPE_FORWARD_ONLY problem " New topic
Author

Resultset + TYPE_FORWARD_ONLY problem

Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
Hai Friends,

The resultset I am obtaining from a query is TYPE_FORWARD_ONLY. And the cursor is now pointing to the last row.
How can I move this cursor to the first row.(The problem is th result set is TYPE_FORWARD_ONLY).

The Problem is coming only when executing Stored Procedures.
------------------
Other Sql queries are executing nicely.


I am executing the query and the table is changed dynamically using a TableModel.




In the tablemodel following code is executed.




But the results.last(); is not getting executed.

java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY

then how can I get the numrows.

IF I use





then the cursor will reach at the end.
And when executed the JTable is created with
java.sql.SQLException: Result set type is TYPE_FORWARD_ONLY as content.

Any one have some idea to cure it.

The Problem is coming only when executing Stored Procedures.
------------------
Other Sql queries are executing nicely.

Ram Mohan.
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Ram,

Before I tell you anything else. Change your screen name. You must do this because the moderators here will get upset with you if you don't. Your publicly displayed name should be Ram Mohan not Sliders Field.

You can change your display name by clicking the link at the top of the page for "My Profile" and then clicking the link for "View/Update Profile".

Anyway...

if you want a specific cursor then you need to specify it. You are specifying this for Statement but where do you do this for PreparedStatement? You have to do this for PreparedStatement too.

Like



(I edited the above to fix the layout I hope...)
[ November 09, 2005: Message edited by: Maximilian Stocker ]
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Sorry you said Stored Procedures and not Prepared Statements.. but same idea. Look at the method prepareCall(String sql, int resultsettype, int resultsetconcurrency)
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30370
    
150

"Sliders Field"
Max is correct. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.


[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
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
Thankx

I will look method prepareCall(String sql, int resultsettype, int resultsetconcurrency) for stored procedures.As you find I was excuting query without looking the contents. now I have to check the query stored procedure or not.

But still I don't know how to do that validation.

Keep in touch.

Ram Mohan.
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Ram,

To be perfectly honest I wouldn't have an editable JTable backed by a live cursor anyway. It's kind of expensive from the DB side of things and if the user goes for lunch two bad things will/could happen. 1) Those resouces are tied up on the database and could be locked as well 2) Your connection could/should time out and then your GUI will have an unpleasant error.

It would be better to just use a forward only cursor and dump all the contents into some sort of Collection. ArrayLists are nice. Then use that Collection for your JTable.

For updates you can issue UPDATE queries providing you are selecting the primary key as part of your query.

Anyway I think that is a better route to go.
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
YES I think you are right. I will update my program to store the resultset
in a VECTOR and I will pass this vector to the TableModel table generation.

The truth was, I am not very much familiar with tablemodel And in a trial and error method I got it correct with above program. So changing the tablemodel by accepting vector may be a HIMALAYAN hurdle for me.
But believe it comes in my way. I will TRY.


Ram Mohan.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Resultset + TYPE_FORWARD_ONLY problem