Originally posted by Scott Selikoff:
I do have a unique id (just not one generated at the time of the update). I try to avoid PLSQL solutions when I can, I was hoping for something in pure SQL.
Ironically, adding the ORDER BY caused actual deadlocks instead of "deadlock exceptions" from oracle since they were all grabbing the first record. Oh well.
I decided to solve the problem using java method synchronization on the 2 sql queries since the environment is such that its a single jvm with dozen of threads. It still uses manuel committing for database protection, but so far seems to be more reliable than what I had before.
Originally posted by Scott Selikoff:
Is it psosible to perform an update in JDBC (preferably via Oracle) such that you can perform an update and read the results in a single SQL statement?
Other restrictions are that the row does not have any generated keys. I'd like to do the equivalent of the following "Fetch me a single open record, change a column value to be closed, and tell me which record I updated"
I can do this with 2 statements using SELECT FOR UPDATE then performing the UPDATE but in high traffic this throws deadlock exceptions in oracle about 5% of the time.
The query that performs the update is:
UPDATE myTable
SET status ='Closed'
WHERE id IN (SELECT id
FROM myTable
WHERE status = 'Open' AND ROWNUM = 1)
This will perform the update I want but it won't tell me which record was updated especially if there are multiple threads executing at the same time with this query.
[ March 23, 2006: Message edited by: Scott Selikoff ]
Originally posted by Ryan Johnson:
We have a background process that runs every few minutes. It opens up several sessions and each performs works. When we take the system down for maintenance we have a korn shell script that kill -15 the java threads.
Problem is that even though autocommit is off insert,update,delete that have been made are being committed when the session shuts down and we would like it to roll back.
Writing code to handle a graceful shutdown and have it roll back would be a significant effort. Is there a jdbc flag that will tell oracle 'if this session dies on you rollback and don't commit unless we specifically say so'.
Originally posted by jaikiran pai:
Well, thats exactly, what i wanted. Suppose it had 10000 rows and i set a fetch size of 500. One first invocation, i need to get the 1-500 rows then on second invocation 501-1000 rows and so on, which i think is not possible with the approach mentioned by "Stu Derby".
Originally posted by jaikiran pai:
Hi,
We have a J2EE application deployed on Jboss. We have a requirement wherein, we have to execute a query to retrieve a huge ResultSet. This can run into millions of records. Naturally, we have already seen the OutOfMemory error. Is there any way(API) through which i can retrieve the ResultSet in chunks?
Originally posted by George Stoianov:
Hi Menon,
Can you please eloborate on why count(*) would not return the correct results in Oracle or point to a place to find some explanation.
Thinking about the record count I think it is kind of interesting how one has to approach this, are there examples of this in your book?
In Java you have to abstract and organize the same operations in one single location and reuse them to have good OO and code reuse, but it seems taking into account how Oracle works and the cost you end paying on the database side makes this impossible.
I will give an example so you can comment on that. Let us say I make a method that accepts a connection and a table name in the method I issue a count(*) and retrieve the number of rows which the method returns to my calling method. This in my mind is good OO and reusable functionality that fits well in any program. How would you rework that taking into account the imperfect results from count(*)?
I do a lot of web development and usually a record count is printed when displaying a table yes I can keep a counter and append the count to the string holding the table in a place where it appears on top of the output or bottom whatever, but that means I have to duplicate this code for every loop for every table, that is not good OO and leads to problems. If I later find a better way I then need to go and change my code in all of those places and possibly introduce new problems.
Thanks in advance,
George
Originally posted by Jeanne Boyarsky:
Unfortunately, "Menon" doesn't follow our naming policy. A first name (or initials) and last name is required. Can you change it back?
It is ok to sign your posts with Menon as you have been doing, it's just the display name that needs it.
Originally posted by stu derby:
Yes, agreed. However, all the JDBC forums I've ever looked at have people clamoring for the best way to do just that.
A very common problem is where they have a web system and want to display a "page" of results; maybe rows 31 through 40, and they have a business requirement to display "Page n of m" along with the data.
R. M. Menon, how would you do it, generally?
Originally posted by Bill Johnston:
I wonder if Menon might have something on that in his new book?
Originally posted by George Stoianov:
As there is no method... that I know of in java to return the record count and looping through all recs to get a count is not very efficient.
You may create a method that executes a
and returns the result as a java long in java that way you can get counts for any table they will run in the db making them faster and improving the performance of your application.
Please note that in some databases it is advisable to put the primary key in the count function.
Hope this helps,
george
Originally posted by kwame Iwegbue:
thanks guys. but thats so odd that there's no clear method for doing this like getColumnCount() ?!
Also, make sure that your con variable is local and that you always close each Connection. Do not leave Connection objects hanging around like this.
Originally posted by Ilja Preuss:
Well, as an "Agilist", I was actually talking about the automated kind of tests that you run by the press of a button after every little change to the system.
Originally posted by Ilja Preuss:
Anyway, all I wanted to say is that "you payed for the db, so you should use it's feature to the maximum" sounded overly simplistic to me - even harmful if taken literally. If after careful consideration of *all* the influences on a project you decide to put more code into the DB, more power to you.