Same Connection for two PreparedStatements?

Dear Experts,
Is it better to use two connections for two different PreparedStatements ?
Let me elaborate:
I have to iterate in a loop & for each iteration I need to
a) Select a row.
b) Possibly update that row depending on some condition.
My question is:
Do I use only one connection, & then use the select & update (one after the other) on the same connection,
Or do I use two different connections & have two separate preparedStatements & just execute them each time in the loop?
Thank you for your anticipated responses.
Sandeep

Here is how I would approach this issue:
In the database table, I would add another column called 'version'. When the record is first inserted into the database, I would set version=1. Each time the record is updated, I would increament version by 1 (example: 2, 3, 4, etc).
Now, in your program, I would open a conneciton, then I would read in all the records at once (via a query) into an array. I would not read in all the fields from each record, just read in the fields you need to examine, plus read in the 'version' field. Close the resultSet and preparedStatement since you dont need them anymore for the query because you transfered all the data into the array.
Next, I would use the same connection to create a new preparedStatement for updating. Loop through the array looking for a record you need to update. If you find one, I would update the record but add to the sql's 'where' clause a test to ensure the record has not been altered since the last time it was updated (check the 'version'). Example:
update person set firstName='Joe', version=(23+1) where verson =23.
Where '23' came from the 'version' you stored in the array you previously read in. If the update returns with a '1', it
was updated successfully. If it returns '0', the record was updated while you were evaluating the record. If that happens, take whatever action you think you need to take. Note there is no need to set up a transaction.

Similar Messages

  • How to have two seperate Itunes on the same computer for two Ipods?

    Is there a way to have two separate Itunes downloaded on the same computer for two different Ipods? My sister got a new Ipod and she wants to hook it up to the computer but when ever she does it just pulls up my Itunes and has all of my songs on there. How can we each have our own Itunes?

    There's many ways to accomplish this. You could create two accounts in Windows. That way everything is completely separate. Or, you could manually manage your music in iTunes -- this way it won't automatically sync your music onto her iPod. More info here:
    http://docs.info.apple.com/article.html?artnum=61148
    http://docs.info.apple.com/article.html?artnum=93779

  • Is it possible to use the same Switch for two different clusters.

    I have 10g Rac setup on windows.
    Now I am planning to install 11gR2 on different servers.
    Is it possible to use the same Switch for two different clusters.

    user9198027 wrote:
    I have 10g Rac setup on windows.
    Now I am planning to install 11gR2 on different servers.
    Is it possible to use the same Switch for two different clusters.
    Yes.  Technically there will not be any conflict as long as the private addresses used by the 2 clusters do not collide, and provided that the switch's port capacity and bandwidth will not be exceeded.
    Your NA (netadmin) can also configure the switch to separate the 2 Interconnects from one another (called partitioning when using Infiniband) - if the switch supports such features.
    A major consideration is not to make the switch, public. That typically cause a range of problems and can have a serious impact on an Interconnect. But using 2 private networks on the same infrastructure should not have the same problems - if configured and implemented correctly.

  • Same id for two users

    Hi,
    Is it possible to have same ID for two different users? 
    ID
    http://forums.sdn.sap.com/profile.jspa?userID=3882846 
    is not me. 
    Thanks

    Thanks for the reply.
    Ofcourse its not a big issue with me.  My only concern is if tomorrow for whatever reasons,  id no 1 is to be penalised for whatever wrongdoings,  the axe should not fall on id no 2 by mistake....
    Thanks again.

  • I used te same email for two iPhones

    I used the same email for two iPhones all the contacts from the other phone came to mine how to undo that or how to erase

    On your iPhone go to settings, then iCloud, at the bottom of that screen click the big read button to delete account. Save your contacts just in case when it asks, you can delete them later. Now start over and create a new apple id. Use re new id to create your iCloud's account. Do this for every phone. Every phone has its unique apple is for iCloud, but in iTunes use the original apple id so you can continue to share music and apps

  • Can I use the same iTunes for two iPods

    Hey guys I wanted to ask if it is possible to use the same itunes for two ipods. I have an ipod touch 4g and ipod shuffle. would music be erased if I did  or would their be any problem if I do so. Thanks in advance

    No problems if you do it right. See:
    How to use multiple iPods, iPads, or iPhones with one computer
    What is the best way to manage multiple...: Apple Support Communities

  • Routing issue- seeing same IPs for two hops

    Hello All,
    I'm seeing two same IPs in the traceroute output. Is that due to routing issue that nexhop is as the same device for the first time?
    Log:
    6  10.30.102.26  61.060 ms 10.30.100.142  61.266 ms 10.30.102.26  61.071 ms
    7  10.30.102.26  61.139 ms  61.211 ms 10.61.191.2  60.948 ms
    Can you  guys help me to fix the issue??
    Regards,
    Thiyagu

    Are you load balancing anywhere?
    6 10.30.102.26  61.060 ms
       10.30.100.142  61.266 ms
       10.30.102.26  61.071 ms
    7 10.30.102.26  61.139 ms  61.211 ms
       10.61.191.2  60.948 ms
    HTH,
    John
    *** Please rate all useful posts ***

  • Can i load two different itunes on the same computer for two different ipods?

    Can I load two different itunes on my computer for two different ipods?  Or how can I get it so that when I click on itunes, only my songs come up and not my wifes?  And the same for her.

    Yes.  The simplest way is to have separate Windows accounts for each user.  When either user runs iTunes, he/she will have a separate library with distinct content, playlists, etc., and can sync individual iDevices as needed.

  • How to use same DFF for two different forms with :BLOCK.field reference

    Hi,
    Can anyone suggest how to use the same dff in two different forms by using :BLOCK.field reference.
    Scenario is the same DFF is referenced by two forms, viz. Form-1 & Form-2.
    Form-1 Reference Field is :BLOCK.field name, but the same block is not available in Form-2, which throws an error while opening it.
    Any pointers please.
    Thanks,

    In the environment I currently have access to do not have similar setup.
    Let say you setup the DFF1 default value to $HEADER.customer_name, the name of the DFF is CUSTOMER_NAME, description can be anything.
    In DFF2, default value should be a SQL, where you can reference the DFF1. For example, SELECT DECODE($FLEX.CUSTOMER_NAME, 'ABC', 1, 'DEF', 2, NULL) FROM dual
    In this case, you can reference the DFF1.

  • How to install two iTunes on same PC for two iPods?

    My family now proudly owns 2 iPods, but we only one PC. So it needs to host two iPods, with their resepctive iTunes on it.
    I thought this was going to cause problems, and worried that installing iTunes for the most recently purchased iPod would overwrite the existing programme, wipe the music off it and cause my middle daughter to kill me. The guy in the shop said, no problem - create a new User Account and install the new iTunes on that, and it would be OK. So I did.
    I got a bit worried when the install prog wanted me to put the new iTunes into the same folder that the old one was in, (even though I was logged in as a different, new user) so I found a new location for it and went ahead.
    Guess what - it wiped the old iTunes anyway. When I opened up the old one, it had been overwritten anyhow.
    I did a system restore to try and get it back to the previous setting - deleting the new user I had created. And went back into the old version of iTunes to see if the music files had come back. But it wouldn't even run - saying that some files were now missing.
    This is doing my head in, it's happened before (and I had to buy Copypod to restore the stuff on my iPod).
    How can you get two copies of iTunes on the same PC running two separate iPods?!! And how can I get the overwritten files back?
    Various   Windows XP Pro  
    Various   Windows XP Pro  
    Various   Windows XP Pro  

    You don't need two copies of iTunes. There are a couple of methods for using more than one iPod on a single computer. Have a look at the article linked below. Method one is to have two Mac or Windows user accounts which by definition would give you two completely separate libraries as each account using iTunes will have it's own iTunes Music Folder. Method two is to set your preferences so each iPod is updated with only certain playlists within one library. Have a look anyway and see what you think and go for whichever you feel suits your needs best: How To Use Multiple iPods with One Computer

  • Service Registry: Publish the same service for two different business syst.

    Hello all,
    i am trying to publish a webservice in the Service Registry of a PI 7.1 EHP1 and i'm facing a problem. I have configured two Business Systems that use the same Service Interface, let's say Dev and Qua systems. So, this two business systems can be senders of the webservice. I have been able to publish the first Sender Agreement properly, but when i try to publish the second Sender Agreement as the service is already publish i get the following error:
    One service definition with the same name 'SI_I015_EneGISDeviceLocationServicesInternalMessage_In(urn:enemalta.com.mt:iubs:integrations)' found; do you want to delete this object from the Services Registry and continue publishing?
    I've been told that this error might be a permission problem but the user i am using has all the permissions required. Does anyone know how to solve this issue?
    Thank you very much in advance!
    Roger Allué i Vall

    Hi Roger,
    Is that problem solved for you?
    I am looking for inputs on a similar issue here. I need to have a single service but with two different endpoints (for two sender business systems) published in SR.
    Thanks,
    Marz

  • Same setting for two file adapter but different output

    Hi ,
    I am having two receiver file adapter for two differrent scenario with same settings but different structure.
    I want the output of the file for both the scenario should be displayed line by line but it is working fine for one scenario.File type,file encoding and FCC are same in both the interface except the fieldsnames in FCC.
    When i check both the output file i found that the scenario which is working fine  having OA OD hexadecimal value at the end of line of each line.and the second scenario which is giving the output in single line is having only OA.
    waitng for Valueable inputs!!!
    Thanks
    Santosh

    Hi Santosh,
    Kindly elaborate your question.
    it would be helpful if you post the content conversion parameters of the erroneous file channel.
    Regards,
    Varun

  • Will a sequence return same value for two different sessions?

    Is there a possibility that a sequence will return same value to two different sessions when it is referred exactly at the same instance of time?

    @Justin... Thanks for your insight; indeed, we too feel this shouldn't ever happen and never heard of it either, but there it is. (No, we haven't logged a TAR yet -- whatever that is -- partly because it didn't occur to us and partly because we only recently came across the issue and sensibly want to do some testing before we cry foul.)
    However, the code is pretty straight-forward, much like this (inside a FOR EACH ROW trigger body):
    SELECT <seqname>.NEXTVAL INTO <keyvar> FROM DUAL;
    INSERT INTO <tblname> (<keyfield>, <... some other fields>)
    VALUES(<keyvar>, <... some other values> );
    (where <tblname> is NOT the table on which the trigger is fired). This is the only place where the sequence is ever accessed. The sequence state is way below its limits (either MAXVALUE or <keyfield>/<keyvar> datatype size).
    In this setup, end users sometimes got an out-of-the-blue SQL error to the effect that uniqueness constraint has been violated -- as I said, we used to have a unique index on <keyfield> -- which leads us to assume that the sequence generated a duplicate key (only way for the constraint to be violated, AFAIK). We released the constraint and indeed, using a simple SELECT <keyfield>, COUNT(*) FROM <tblname> GROUP BY <keyfield> HAVING COUNT(*)>1 got us some results.
    Unfortunately, the <tblname> table gets regularly purged by a consumer process so it's hard to trace; now we created a logger trigger, on <tblname> this time, which tracks cases of duplicate <keyfield> inserts... We'll see how it goes.
    @Laurent... winks at the CYCLE thing Our sequence is (needless to say) declared as NOCYCLE and the datatype is large enough to hold MAXVALUE.

  • How do I use the same profile for two users on the same computer

    I use my laptop both at home and at work. And in each venue I use a different user log on. But I wish to have firefox use the same profile for each user log on. How can I get firefox to point to the same profile for each user?

    Note that only one user (Firefox instance) can use a profile folder at the time, so if you would switch the Windows user to another account then you would first have to close Firefox.
    * http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows
    * http://kb.mozillazine.org/Shortcut_to_a_specific_profile
    * http://kb.mozillazine.org/Using_multiple_profiles_-_Firefox
    * http://kb.mozillazine.org/Bypassing_the_Profile_Manager

  • How can I use the same contacts for two users

    MY wife and I are using the same account. I want to give her a seperate log in account (user). All is working fine excempt for "contacts". These are at the moment empty. How can I get our contacts also in her new contact list.
    Are there any other things I should also look for, in executing this exercise

    Hi Iemke Kuijper!
    I have two articles for you that will help you achieve this goal. First, here is an article on exporting your contacts files and importing them:
    Contacts: Export and import your contacts
    http://support.apple.com/kb/PH11586
    This next article will help you get the contacts file from your user account into your wife’s user account:
    OS X Mountain Lion: Share files with others who use your computer
    http://support.apple.com/kb/PH10636
    Thanks for using the Apple Support Communities!
    Cheers,
    Braden

Maybe you are looking for

  • I Photo won't update

    I have a Macbook pro I bought in Dec. The last two iphoto updates will not update via software update or downloaded installer, Any Ideas. I work nights and sometimes it is hard to call tech support! HA! So Hope I am missing something ? again any Idea

  • Nokia Music Voucher - Lumia 520

    My lumia 520 mobile, i cant download music from Nokia music free, the eror occurs that redeem a code Moderator's note: The subject was edited as we the post was moved to the appropriate board. Solved! Go to Solution.

  • OC4J_DBConsole_test_orcl not found

    Hi I am facing a problem to start enterprise manger ----------------- it is single instance 10.2.0.5.0 OEL5.0 I wan -bash-3.2$ emctl start dbconsole TZ set to Asia/Karachi OC4J Configuration issue. /ora/app/oracle/product/102/db1/oc4j/j2ee/OC4J_DBCon

  • Word processing apps

    Does anyone know of a word processing app that supports comments (as in the comments functon which is available in e.g. Microsoft Word 2007)?

  • Internet via Sprint bluetooth

    I will be purchasing an iBook G4 within the next few weeks and would like to also upgrade my cell phone to bluetooth. I am a Sprint customer in the USA. As far as I can tell the only bluetooth phones offered by sprint are the LG PM-325 and the Ericss