What if i need more than one prepareStatements per connection

hi all!!
Please take some time to look into this scenario.
On the front end: User enters/ updates his/her records and submits. An ArrayList of object goes to backend.
On back end: i have to loop for the size of the ArrayList submitted and see if some record is to be updated or inserted.
Now at back end i do following steps:
I have only one Connection object named connection.
Step 1:
query (say query1 )to see if the record in DB exists for the primary key as extracted from the element from ArrayList. So one prepareStatment ( say prepareStatement1) for this. I write a query and execute :
prepareStatment1= connection.prepareStatement(query1);
Step2 :
A query ( say query2) to update Data in DB. And i have a separtae prepareStatement for this and i execute
prepareStatment2 = connection.prepareStatement(query2);
Sep3
A query (say query3 )to insert Data in DB. And i have a separtae prepareStatement for this and i execute
prepareStatment3 = connection.prepareStatement(query3);
Step4:
for: size of arraylist:
1. take out the element at ith index from the list.
2. see if the record exists i.e execute step1 and see if resultSet.next() is true.
3. if record exists step2 applies so execute update query
4. if record doesnot exist then go to step3 and execute insert query
A weird thing happened .. insert was running fine but update was not. May be i was not checking appropriately. BUT the error that occurrd was that
[Microsoft][ODBC SQL Server Driver]Connection is busy with
results for another hstmt.
So i changed my path and in loop i prepareStatement and execute query to see if record exists or not and store the result in some boolean variable and then close this prepareStatement. and if the result existed again prepare a statement for update or else prepare a statement for insert and execute the respective.
and then again close this prepareStatement and go for next iteration of loop
so each iteration i am preparing statement and then closing it BECAUSE Connection doesnot allow more than one statement per connection at one time. Am i right.??
what should i do.? Although i have solved problem by closing and preparing in loop but that is so inefficient. Is there some elegant way???
please reply.
PS: I am using ms sql server 8.0 as my DBMS. I am developing web application using Sun Creator.

No, you can use as many PreparedStatements as you like, all from one Connection, and you can keep them open as long as you like. (I do this with no problems.) Where you will run into problems is when you are trying to use two ResultSets at the same time. That's what the error message means, it just doesn't use JDBC terminology.

Similar Messages

  • Why do we need more than one retained earnings accounts & what is the use?

    Hi FI Experts,
    Why do we need more than one retained earnings accounts, what is the precise use of two?
    I know the retained earnings account is used to carry forward the balances during the year end to the balance sheet and there by making the p&L A/cs balances as zero.
    I guess the second one is used for different valueations for example  as depreciation accounts for different valuations will have different retained earnings accounts.
    Kindly correct me if I am wrong and eloborate on the use having more than one retained earnings accounts.
    with regards
    Ramesh Y

    Hi,
    Well, separate retained earnings accounts are used for parallel financial reporting, it means when you need to report in accordance with, for example, local GAAP and IFRS or US GAAP at the same time. Several retained earnings accounts  are necessary when the company chooses account based approach for parallel reporting. (GL accounts are broken down into several groups, for example you use different accounts for IFRS valuation, for local GAAP and they are also shared accounts common for both principles.)
    m.

  • Business graphics need more than one category

    Dear All,
         We have a issue for business graphics need more than one category about web dynpro abap.
       Our data:
       plant   month   qty
      1000   201101  10
      1000   201102  30
      2000   201101  30
      2000  201103   40
    Now we need one category for "plant" and other category  for "month", Data is qty.

    Hello Bill,
    could you explain bit more about your requirement? How would you like the graph to be renderded with two categories. Can't you club Plant and Month into one single category (1000-201101) and display it?
    BR, Saravanan

  • How do I configure the Airport utility to allow more than one rule per port?

    How do I configure the Airport Utility (AU) to allow more than one rule per port?
    I am on a home network, with broadband cable modem.  I have my airport extreme connected to the broadband modem.  I have 2 servers in my home that need to be accessed remotely from time (SSH), and they also serve data for an iphone app, so I'm using a variety of protocols.  The problem I'm running into is that AU seems to only allow one rule per protocol, so if I go to add another address for access on a specific port that is being used by one of my servers, AU tells me "The Port Mapping Entry Already Exists". 
    I need to be able to allow SSH on both of my servers, for instance.  Am I missing something?  Is this doable with AU?
    Thanks for any insight.
    Khalid

    The Port Mapping "rules" on the AirPorts will allow you to: 1. Map a single port to a single IP address OR 2) Map multiple ports to a single IP address.
    What you won't be able to do is map a single or multiple ports to multiple IP addresses.

  • Is it possible to datamerge more than one image per page?

    I am building a product catalogue using datamerge.  Is it possible to data merge more than one image per page? (ie I have a logo, product image and dimensioned drawing to go with each product page)
    What would the coding be for the Data Field Name?
    Would it be
    @Logo
    @Product Image
    @Dimension Drawing
    Add image fields in the data source file
    By adding image fields to the data source file, you can allow a different image to appear on each merged record. For example, when you merge documents that include information from various companies, you may want to include an image of each company’s logo as part of the merge.
    Open the data source file.
    At the beginning of the data field name, type an “at” symbol (@) to insert text or paths that refer to image files.The @ symbol is required only in the first line; subsequent lines should include the image paths. Paths, which are case-sensitive, must follow the naming conventions of the operating system in which they’re stored.
    If you get an error message when you type the @ symbol at the beginning of the field, type an apostrophe (') before the @ symbol (such as '@Photos) to validate the function. Some applications, such as Microsoft Excel, reserve the @ symbol for functions. 
    (Windows) Example of image references in data source file
    Bill Tucker
    36
    C:\Photos\BillTucker.jpg
    Dat Nguyen
    53
    C:\MyDocuments\dat.gif
    Maria Ruiz
    26
    C:\Photos\Ruiz.psd
    (Mac OS) Example of image references in data source file
    Bill Tucker
    36
    Mac HD:Photos:BillTucker.jpg
    Dat Nguyen
    53
    Desktop:Family:dat.gif
    Maria Ruiz
    26
    Mac HD:Photos:Ruiz.psd
    You can use InDesign to view the path of an image on your operating system. Insert an image in an InDesign document, and then use the Links panel to view the image’s location. With the image selected, choose Copy Info > Copy Full Path from the Links panel menu. You may need to edit the path after you paste it in your data source. This technique is especially useful for images on a server. 

    anna-rees wrote:
    I am building a product catalogue using datamerge.  Is it possible to data merge more than one image per page? (ie I have a logo, product image and dimensioned drawing to go with each product page)
    What would the coding be for the Data Field Name?
    Would it be
    @Logo
    @Product Image
    @Dimension Drawing
    Yes, pretty much exactly as you describe. You would then just add those fields to the boxes in your page. I tend to add an apostrophe before the @ symbol in Excel so it doesn't think it's a function - as per text you quoted above.
    If you get an error message when you type the @ symbol at the beginning of the field, type an apostrophe (') before the @ symbol (such as '@Photos) to validate the function. Some applications, such as Microsoft Excel, reserve the @ symbol for functions.

  • Importing From Excel file will not import assignments correctly where there are more than one assignment per task

    I am trying to import an excel file ... see below.   It appears if you select both Tasks and Assignments tables it will not allow you to do this, says file is not in a project recognized format.  So I import Tasks tab first then run the
    wizard again and import the assignments tab while selecting merge with project option.   This works with one exception:
    If there are more than one assignment per task.  It does not merge in the 2nd assignment, only the first.
    Is there a way to import a task with 2 or more assignments?
    Background
    To figure out what the format for the file needed to be, I started with a MPP file and from project saved as Excel and selected the "Project Template" file.  Now I am trying to import that XLS to see how it works
    ID
    Active
    Task Mode
    Name
    Duration
    Start
    Finish
    Predecessors
    Outline Level
    1
    Yes
    Auto Scheduled
    DS001
    3 days
    June 17, 2014 8:00 AM
    June 19, 2014 5:00 PM
    1
    2
    Yes
    Auto Scheduled
    MT001
    3 days
    June 17, 2014 8:00 AM
    June 19, 2014 5:00 PM
    2
    3
    Yes
    Auto Scheduled
    CT001
    1 day
    June 17, 2014 8:00 AM
    June 17, 2014 5:00 PM
    3
    4
    Yes
    Auto Scheduled
    CT002
    2 days
    June 18, 2014 8:00 AM
    June 19, 2014 5:00 PM
    3
    3
    5
    Yes
    Auto Scheduled
    DS002
    1 day
    June 20, 2014 8:00 AM
    June 20, 2014 5:00 PM
    1
    6
    Yes
    Auto Scheduled
    MT002
    1 day
    June 20, 2014 8:00 AM
    June 20, 2014 5:00 PM
    2
    7
    Yes
    Auto Scheduled
    CT003
    1 day
    June 20, 2014 8:00 AM
    June 20, 2014 5:00 PM
    4
    3
    Task   Name
    Resource Name
    % Work Complete
    Work
    Units
    CT001
    Engineer1
    0
    8h
    100%
    CT002
    Engineer2
    0
    16h
    100%
    CT003
    Engineer1
    0
    8h
    100%
    CT003
    Engineer2
    0
    8h
    100%
    Andrew Payze

    Andrew,
    I did a quick test using your example although I didn't include the Predecessor or Outline Level fields to keep things a little simpler. I imported the Excel data into a new Project file with a single import of task and assignment data. It is very important
    to set up the Excel Workbook correctly. On Sheet 1 I entered the task data (Name, Duration, Start). I did not include the ID or finish date as that is redundant - Project generates its own ID and will calculate the finish date based on the start date and duration.
    On Sheet 2 I entered the assignment data basically just as you show it except I didn't include the Units.
    The data imported as expected.
    John

  • Can I have more than one iphone per email account?

    When my son got his iphone 4s I used my email address since he didnt have one yet.  I have since gotten an Iphone 4s also, but when I went to activate it I had to put it under another email account, since mine was used for my sons iphone, so I used my husbands.  My husband now has an iphone on order and I was wondering if there was a way of having more than one phone per email account?

    I would set up a new email for him.  That will give you a new icloud account.  Also any apps that he downloaded with your ID will forever be linked to that ID and can only be updated with that ID.  If that is a problem then you might delete those apps and download them again with the new ID ( and if they were paid apps you need to pay again)

  • Error: You have more than one Creative players connected. - Recovery Tool for ZEN

    My Zen 4GB cannot be turned on anymore after a failed firmware upgrade (The installation hung up). I tried to run the firmware upgrade executable file again but the player must be on. So I tried to hardware reset by switching the power slide on while pressing the play button, but it still doesn't start. I downloaded and ran the Recovery Tool while the player was connected, but an error message appeared: "ERROR: You have more than one Creative players connected. Please remove all but one, click "OK" to exit and then run this program again." - There was no other players connected but the ZEN. Please help... What can I do

    I have this very exact same problem with the same model. Did you ever find a solution to this?

  • Hacking application id equals() to allow more than one row per "primary key"

    I have a read only entity whose primary key is not the real primary key
    on the underlying table. The result is that I get more than one row per
    "primary key". This is what I want. However KODO will not allow me do
    it, because I am storing the collection in a HashSet() and the equals()
    method on the application id object ensures that this set contains no
    duplicates (as defined by the application id). At least thats how it
    seems to behave.
    So, I have hacked the equals() method to do this:
    public boolean equals (Object ob)
    if (this == ob)
    return true;
    // Doing this because we expect more than one row from
    // REF_CODES for the same domain/shortCode combination.
    // This is ok to do (I guess?) as long as we are only
    // doing selects using this class.
    return false;
    Will this hack have any side effects? Is there another option? Like
    using a list collection? Is so, which collections are supported?
    Thanks,
    Mike.

    The "primary key" I am using it already a compound key of two columns.
    The real key on the underlying table is a three column key. But the
    problem is that the table represents two different application level
    entities. I could deal with it when I was hand-writing SQL (I could do
    a distinct for example) but now I am relying on foreign key
    relationships since I moved to JDO. Not sure what to do. Best solution
    is to rework the table, but there is a lot of legacy code (that other
    teams use and maintain) relying on this table. I guess I'll use the
    weekend for inspiration ;-)
    Steve Kim wrote:
    This sounds like a dangerous operation. Even if this works now, I
    cannot promise future compatibility... and in fact may result in bad
    data (for example in caching both at the PM and PMF level) Is there no
    other field that you can reference as part of the primary key? Primary
    Keys can be multi columned (e.g. last_name, soc_sec_number)
    Mike Hogan wrote:
    I have a read only entity whose primary key is not the real primary
    key on the underlying table. The result is that I get more than one
    row per "primary key". This is what I want. However KODO will not
    allow me do it, because I am storing the collection in a HashSet() and
    the equals() method on the application id object ensures that this set
    contains no duplicates (as defined by the application id). At least
    thats how it seems to behave.
    So, I have hacked the equals() method to do this:
    public boolean equals (Object ob)
    if (this == ob)
    return true;
    // Doing this because we expect more than one row from
    // REF_CODES for the same domain/shortCode combination.
    // This is ok to do (I guess?) as long as we are only
    // doing selects using this class.
    return false;
    Will this hack have any side effects? Is there another option? Like
    using a list collection? Is so, which collections are supported?
    Thanks,
    Mike.

  • HT1206 I have a computer with 2 users and each of us have I tunes authorized but only one of us can cloud sync our purchases what can I do I need more than one ID available

    Help please I need to have more than one Itunes Id

    Well you need to understand the behavior of h-reap or what it's called now, FlexConnect. In this mode, the clients are still remembers on the WLC until the session timer/idle timer expires. So switching between SSID's in h-reap will not be the same when switching when the AP's are in local mode.
    Take a look at the client when connected in FlexConnect in the WLC GUI monitor tab. Thus will show you what ssid and vlan the client is on. Now switch to a different ssid and compare this. It's probably the same because the client has not timed out. Now go back to the other ssid and look again. Now on the WLC, remove or delete the client and then switch to the other ssid at the same time. Or switch SSID's and then remove the client. The client will join the new ssid and in the monitor tab, you should see the info.
    There is no need to have clients have multiple SSID's unless your testing. Devices should only have one ssid profile configured to eliminate any connectivity issues from the device wanting to switch SSID's.
    Sent from Cisco Technical Support iPhone App

  • Isd there a way to have mail use more than one address per person from the address book?

    Have a group in address book and some of the records have more than one email address. Is there a way to have mail use both addresses or do I need to have an individual record for each email I want to send to?

    This article seems to describe a way to do what you want.

  • Can you have more than one movie per page?

    Hi, I am creating a web site and have some movie content on some of the pages. Can you have more than one quicktime file on each page? Reason I ask is that on one page I have put 3 movie files but only one shows up when I run the site online. I am not using .mac. The website is on grapeape dot co dot uk and if you look at the examples page you should see what I mean. I get one video that works and 2 large "Q"'s where the other videos were. Odd because it works locally. Any ideas? Many thanks.
    Ben

    Just noticed something. If you leave it until the first movie caches or preloads - the second one appears. Is there a way round this at all? Thanks. Ben

  • How do I add more than one video per track/layer?

    Hi.
    Could someone please advise me how I can add more than one video to a track/layer?
    I'm cutting and pasting parts and each time I paste, a new track/layer is added.
    The final video is going to be approximately 5 minutes long.
    I am 17 seconds in and have 54 tracks already!
    How do I stop this?
    Thank you very much
    J

    More video tracks. This is actually what you want.
    Unless you're just making a still image (like Photoshop), multiple layers give you control to animate each individually. (If it's just a Photoshop comp you're after, you may want to create it in Photoshop)
    If you want to move ALL OF THE VIDEO TRACKS TOGETHER, you can use
    parenting or
    precompose those individual layers into a single composition.
    livedocs

  • How can I print more than one slide per page from the iPad????

    Im having problems printing from the iPad. I want to print more than one slide in one peace of paper. 3, 6, 9 ...
    Can any one help?

    Start the print process and click on the Custom layout.  At the bottom you can set the size of the image desired and see how many photos can be placed on the page size selected.
    OT

  • Emailing more than one photo per email message

    Newbie alert: I want to resize and send a handful of photos via email, can't figure out how.
    Thanks, Julie

    Select up to four files at once, then click on the email buton.
    So select more than one file: Click on one then hold the command key and click on the others.
    Regards
    TD

Maybe you are looking for