Conditinal update using PreparedStatement

Hi,
I have situation where in I need to create dynamic sql statements based on user input.
let's say user changes his last name or only first name or some comments field only those fileds changed should be updated in database leaving rest un changed.
I am using PreparedStatement to update (this switched to over come single quote issue with oracle).
if it was simple insert/update i could user statements but how can I do conditinal update using one prepared statement?
any help

From what I've read in the docs and experienced with Oracle drivers, it can't be done. The only way to dynamically create a prepared statement would be to create an update string conditionally based on the changed inputs, then create the PreparedStatement after the conditional checks(same technique you would use to dynamically create a Statement). But that doesn't really fit the criteria laid out by your initial post(only one PreparedStatement for all conditions).
You could also use the CallableStatement and generate your update statement in the CallableStatement the same way you would generate the UPDATE dml using a Statement?
Jamie

Similar Messages

  • [svn:bz-trunk] 12162: Updated using PreparedStatements.

    Revision: 12162
    Revision: 12162
    Author:   [email protected]
    Date:     2009-11-24 08:17:44 -0800 (Tue, 24 Nov 2009)
    Log Message:
    Updated using PreparedStatements.
    CheckInTests: na
    Modified Paths:
        blazeds/trunk/apps/samples/WEB-INF/src/flex/samples/crm/company/CompanyDAO.java

  • [svn:bz-trunk] 12163: Update using PreparedStatements - bug blz-461

    Revision: 12163
    Revision: 12163
    Author:   [email protected]
    Date:     2009-11-24 08:19:56 -0800 (Tue, 24 Nov 2009)
    Log Message:
    Update using PreparedStatements - bug blz-461
    checkintests: na
    Ticket Links:
        http://bugs.adobe.com/jira/browse/blz-461
    Modified Paths:
        blazeds/trunk/apps/samples/WEB-INF/src/flex/samples/crm/employee/EmployeeDAO.java

  • Update using preparedstatement

    Hi
    I am using preparedstatement to fire insert / update statements.
    the update query is taking a lot of time(min 150 ms) where as the insert query takes 0 ms .
    i'm using mssql driver with sql2000.
    what might be the problem???
    Regards
    Ravi

    in case of static the index costs only 38% where as in
    case of dynamic query the index costs 96%
    tht's the reason the dynamic query is taking more time
    also in case of static INDES SEEK is used where as in
    case of dynamic execution INDDEX SCAN is used so
    INDEX SEEK gets the record in one attempt where as
    indexscan scans the whole table to get the record so
    the row count in this case is same as the no of
    records in that table.
    now the question is how can i change the data access
    path /execution plan for the dynamic execution so that
    it should also look for index seek instead of index
    scan.Just to be clear, your Statement query is dynamic, while your PreparedStatement is static. In a previous post you implied that Statement was taking longer, but in this note you are implying that the PreparedStatement is taking longer. I'll let you work out which is which, but it appears that it is in fact a difference in the data access path that is causing the decreased performance.
    I am not a SQL Server expert by any means, but it is possible that someone else can provide you some specific suggestions on what to do next. I am curious why you want to use a Statement vs PreparedStatement (or vice versa). There have been multiple posts discussing the differences and in most cases from a programmers perspective PreparedStatements are superior because they automatically manage many of the data transformations for you (like escape characters for quotes). PreparedStatements are usally recommended by the DBA when a SQL is going to run repeatedly and frequntely to avoid having the database to re-parse the SQL all the time. Having said that, there are still many cases where using dynamc SQL makes sense and yours may be one of these (not sure).
    So, anybody with strong SQL Server have any suggestions for the OP?
    You may want to post this specific performance question out to a SQL Server forum too...

  • Code using PreparedStatement.executeUpdate failing in stress test

    Hello,
    I've just recently learned how to use J-Meter and have been performing tests on my programs. One of which performs the following:
    1. Read user data using a simple SELECT password FROM users where userid = 'xxx'
    2. When authenticated, runs an immediate update using value binding via PreparedStatement.executeUpdate() which is really just updating the lastlogin column of the same table with the current date.
    My application servlet is running on Glassfish and uses a jdbc connection pool defined on it. The problem is that at about 200 concurrent executions per second of the process described above, PreparedStatement.executeUpdate() returns 0 instead of 1 at around 20% of the time. The Glassfish server is on a Sunfire X2100 platform running solaris 10 and has 2 gb ram, while the database on the other end is a Oracle 10G R2 on a PC clone Pentium 4 with 512mb ram also running on Solaris 10.
    This failure rate is too high so what can I do to reduce it?
    Thanks in advance,
    - Owen

    Owen_Ilagan wrote:
    Hello,
    200 per second? That's a pretty decent load. Well, I was told that that was the acceptable load for the same app running on a standard pentium 4 machine I don't see how you can talk about "acceptable load" for a given piece of hardware without taking into consideration what the application is doing. A read-mostly web app will be very different from one that's transaction and/or computation intensive.
    so I would like to get better performance from this Sunfire X2100. Unless of course that figure is wrong... I've just recently started learning to scale my java applications and figuring out how to fine-tune the servers my programs would be running on. I think this is a good article:
    http://www.javaworld.com/javaworld/jw-06-2006/jw-0619-tuning.html?page=1
    I don't know where that setting is on Glassfish so its on default. Is there an optimal setting for it? I run JMeter on a different machine. Good - your clients aren't competing for memory with the server that way.
    Again, I dont seem to recall seeing a setting like that on Glassfish. The current pool setting is at Initial size 8, maximimum size of 32. I already tried increasing it to 200+ but there was no noticeable improvement so I set it back to 32. That's sufficient. You don't need 1 connection per user because of the pool. I use 5:1 as a rule of thumb.
    Threads in my worker pool? Hmmm, let me just clarify that I'm running a rather simple web servlet application using the 1.5 SDK and its not a full-blown EE application. Doesn't matter. There is one thread per incoming request. If the worker thread pool is exhausted the requests are queued up. There's an optimal setting for that, too.
    Well, I dont run into any SQL errors so there is no stack trace to log. Huh? You mean your PreparedStatement can return 0 and not have an exception?
    What happens if you try to UPDATE a user record that isn't in the database? Is that possible?
    When PreparedStatement.executeUpdate() is called, it returns 0 instead of 1. I did put the call inside a try-catch to handle java.sql.SQLExceptions but its not throwing one.Interesting. See question above.
    I hope so.Difficult, but you sound like you're doing a rigorous job.
    %

  • Use Preparedstatement to delete several rows from database

    Hello everyone,
    I am trying to delete multiple rows from database at one time using Preparedstatement.
    It works well when I tried in SQL directly,the sql query is as follows:
    delete from planners_offices where planner ='somename' and office in ( 'officeone', 'officetwo', 'officethree')
    I want to delete those 3 rows at one time.
    But when I am using preparedstatement to implement this function, it does not work. It did not throw any exception, but just does not work for me, the updated rows value always returns "0".
    Here is my simplified code:
    PreparedStatement ps = null;
    sqlStr = " delete from PLANNERS_OFFICES where planner = ? and office in (?) "
    Connection con = this.getConnection(dbname);
    try
    //set the sql statement into the preparedstatement
    ps = con.prepareStatement(sqlStr);
    ps.setString(1,"somename");
    ps.setString(2,"'officeone','officetwo','officethree'");
    int rowsUpdated =ps.executeUpdate();
    System.out.println(rowsUpdated);
    //catch exception
    catch (SQLException e)
    System.out.println("SQL Error: " + sqlStr);
    e.printStackTrace();
    catch (Exception e) {
    e.printStackTrace();
    } finally {
    this.releaseConnection(dbname, con);
    try{
    ps.close();
    }catch (SQLException e){
    e.printStackTrace();
    rowsUpdated always give me "0".
    I tried only delete one record at one time, "ps.setString(2, "officeone");", it works fine.
    I am guessing the second value I want to bind to the preparedstatement is not right, I tried several formats of that string, it does not work either.
    Can anyone give me a clue?
    Thanks in advance !
    Rachel

    the setString function in a preparedStatement doesn't just do a replace with the question mark. It is doing some internal mumbojumbo(technical term) to assign your variable to the ?.
    If you are looking to do your statement, then you will need to put in the correct of # of question marks as you need for the in clause.
    delete from PLANNERS_OFFICES WHERE PLANNER = ? and office in (?,?,?)
    If you need to allow for one or more parameters in your in clause, then you will need to build your SQL dynamically before creating your prepared statement.
    ArrayList listOfOfficesToDelete ;
    StringBuffer buffer = new StringBuffer("DELETE FROM PLANNERS_OFFICES WHERE PLANNER = ? AND OFFICE IN (");
    for(int i = 0; i < listOfOfficesToDelete.size(); i++ )
       if( i != 0 )
           buffer.append(",");
       buffer.append("?");
    buffer.append(")");
    cursor = conn.prepareStatement( buffer.toString() );
    cursor.setString(1, plannerObj);
    for(int i = 0; i < listOfOfficesToDelete().size(); i++ )
        cursor.setString(i+1, listOfOfficesToDelete.get(i) );
    cursor.executeUpdate() ;

  • Using preparedStatement.

    Hi, in the tutorial, it only shows updating of the database sql. Can I use preparedStatement to retrieve data from the database using the SELECT sql?

    Yes.

  • If you are attempting to update using a Mac or PC with which you do not normally sync

    what happens when "If you are attempting to update using a Mac or PC with which you do not normally sync", & they say in step 2 or 3 in order not to loose your stuff "If you are updating your iOS device on a computer with which you do not normally sync , or if you disconnect your device before the sync process is complete, you may notice that some media content that was previously on your device is no longer there. You can restore this content by syncing with the Mac or PC with which you normally sync."
    now what if the pc that was originally used to sync my ipod , has corrupt or  bad systems files that are causing it from working correctly...? when i plug it in to the o.g. operating sysytems (win xp) it doesnt ever recognize or discover the ipod through itunes.  the pc will pop up the "cameras been plugged in, what would you like to do...?" but nothing thru itunes.  now if i reboot & run the windows 7 operating system w/itunes that has backed my ipod before & synced a few times as well, but not the o.g. op system used from the beginning (the very initial set up done on the ipod) it works fine, but DOES give me the warning "updating to 5.0 willdelete some of your apps & media, including ...  ....will only preserve contacts, calenders," ....etc.
    MY HUGE CONCERN IS if i do hit update & go through w/it, & not having been able to sync it to the one normally used to sync my ipod, will that back up i made be able to restore my game seetings, GAME SAVES, & data achievement type information....?
    please, i'm very hesitant to go through w/it, so if you can please help me out here & let me know asap.....i canimagine you're all busy busy, so  i thank you for your time here w/this
    thank you
    mike z
    [email protected]

    Not that hard. One the computer you are using do the following:
    - Transfer iTunes purchases.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    - Transfer other music using a third-party program like one of those discussed here.
    Copy music
    - If you have synced photos you need a paid program like TouchCopy or PhoneView
    - When all the media in on the computer, connect the iPod to the computer and make a backup by right clicking on the iPod under Devices in iTunes and select Back Up
    - Restore the iPod from that backup.
    That computer is now your syncing computer. Note that the iPod backup that iTunes makes does not included synced media like apps or music.

  • Using PreparedStatement.setString() on AS/400 VARGRAPHIC field not working

    Hello,
    I have a database table on an AS/400 that contains a VARGRAPHIC field of length 254. According to all the docs that I've read, I should be able to use PreparedStatement.setString() to set a parameter for that field. However, I never get any rows back when I execute the query. If I run the same query on the AS/400 using strsql, the query runs fine and returns the expected results. Anyone have any ideas?
    Thanks

    The Toolbox driver. In that case you might be better off asking this question in a forum that specializes in that. Go here:
    http://www-124.ibm.com/developerworks/oss/jt400/
    You will find a FAQ section, a mailing list you can subscribe to for discussions such as your question, a bug report page where you may be able to see if your question has already been reported as a bug, and so on.
    I haven't used VARGRAPHICS fields so I have no insight into your problem, except that setting graphics data from a String sounds kind of fishy to me. Good luck.

  • My husband bought an iPad 2.  I have a Mac.  ITunes is in my name but I have turned sharing on.  When we updated to OS5 we lost all the free apps that he downloaded in his user name.  Is there no way to update using my iTunes without losing his software.

    My husband bought an iPad 2.  I have a Mac.  ITunes is in my name but I have turned sharing on.  When we updated to OS5 we lost all the free apps that he downloaded in his user name.  Is there no way to update using my iTunes without losing his software.  He is frustrated using the iPad because he never knows whether to use his user name or my user name.

    Apps are only tied to one account... You can set up two iTunes accounts on your computer, however, and let his iPad sync to his account. If he has never backed up his apps to a computer, however, he will have to redownload all the apps. Afterwards, he can backup to iCloud instead of your computer.
    http://support.apple.com/kb/ht1495

  • How can I script Adobe Reader updates using vbScript, PowerShell or C#?

    I would like to script Adobe Reader updates using vbScript, PowerShell or C#, are there any Adobe API calls I use to do this.  There are several different version that I support and auto update is not an option. I do updates at a specific time of the month. I would like to write a script that would download and install the update for the currently installed version of Adobe Reader (32 or 64 bit) for the version of the OS (32 or 64bit). I can detect the OS version and the Adobe version.  I can download updates but I do not want to hard code anything

    Sabian is correct.
    Most admins download the updates from the ftp site and push via AIP, GPO, SCCM, or some other method whenever it makes sense for them.
    Ben

  • Document Flow not updated using BAPI_GOODSMVT_CREATE

    Hi Experts,
    I am using BAPI_GOODSMVT_CREATE for doing PGR of an inbound delivery.
    Material Document(mblnr) is getting populated but Document Flow of that inbound delivery is not getting updated.Its status is Open.
    Can anyone knows how Document Flow can be updated using BAPI_GOODSMVT_CREATE??
    Regards,
    Puja.

    Hello Puja,
    Goto transaction SPRO, Go to Logistics Execution - Shipping - Basic shipping Functions - Configure Clobal Shipping Data, In this put a tick on Document Flow Update.
    Also refer to the below OSS note.
    http://service.sap.com/sap/support/notes/199703
    Regards,
    Thanga

  • Insert & Update using Writeback in a single Report

    Hi,
    Here is requirement:
    In the single report where the user has to do the Insert & update using the writeback functionality.
    below is the XMl:
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="SUBMITBUTTON">
    <XML>
    <writeBack connectionPool="CSDK">
    <insert>INSERT INTO HSCRTARGETLOOKUP(SLA_TYPE,TARGET_AVAILABILITY,TARGET_MTTR) VALUES ('@{c0}', @{c1}, @{c2})</insert>
    <update>UPDATE HSCRTARGETLOOKUP SET TARGET_AVAILABILITY = @{c1}, TARGET_MTTR = @{c2} WHERE SLA_TYPE = '@{c0}'</update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    Can you please let us know whether both insert & update will work at the same time using a single report.
    Thanks in Advance
    Siva

    Hi,
    Insert & update is working with the Single xml file:
    here it is how i have done:
    in the 1st criteria i have taken three columns and made union with the 3 dummy columns.
    in the 1st dummy column: CASE WHEN 1= 0 THEN HSCRTARGETLOOKUP.SLA_TYPE ELSE NULL END
    2nd dummy column: CAST('' AS INT)
    3rd dummy column: CAST('' AS INT)
    below is the single XML file which is working for both insert & update
    <?xml version="1.0" encoding="utf-8" ?>
    <WebMessageTables xmlns:sawm="com.siebel.analytics.web/message/v1">
    <WebMessageTable lang="en-us" system="WriteBack" table="Messages">
    <WebMessage name="STATES">
    <XML>
    <writeBack connectionPool="XXXX">
    <insert>INSERT INTO HSCRTARGETLOOKUP(SLA_TYPE,TARGET_AVAILABILITY,TARGET_MTTR) VALUES ('@{c0}', @{c1}, @{c2})</insert>
    <update></update>
    <update>UPDATE HSCRTARGETLOOKUP SET TARGET_AVAILABILITY = @{c1}, TARGET_MTTR = @{c2} WHERE SLA_TYPE = '@{c0}'</update>
    </writeBack>
    </XML>
    </WebMessage>
    </WebMessageTable>
    </WebMessageTables>
    Hope it works for you also.

  • How to write SDO_GEOMETRY using PreparedStatements ?

    Hi there,
    I use JDBC and JDK 1.3+
    Currently I'm writing geometries into Spatial by using Strings and
    I meet some limitations for very huge geometries.
    That's why I need to use PreparedStatements and parameters to get
    rid of this limitation.
    My question is how can I write Object types by using JDBC. All
    the sample codes I found use oracle.sql and oracle.jdbc packages.
    My problem is that my code can be used by people that may not
    have an Oracle jdbc driver like "thin" for instance.
    thanks for your help,
    ALI

    Justin,
    I have a PL/SQL package that contains several functions. One of them does selection and filtering of spatial features based on a user's location and preferences. For this purpose a web-application runs this function.
    I would like this function to do the following:
    1. the function is called, user parameters are passed in
    2. a call to a java-stored-procedure is made. This java procedure creates a polygon based on the user's location and preferences.
    3. the polygon is returned to the PL/SQL function
    4. the funtion uses the returned polygon to query spatial features that intersect, etc.
    I can do the call to the java-stored-procedure but where I get stuck is how to get the polygon from java to pl/sql. I can return a String or a number from java but how can I return the polygon (e.g., STRUCT, java object)?
    The current solution uses a work-around by storing the polygon in a temporary table. I would like to change this because once the function has run, the polygon is not needed anymore so I would like to do without having to store the polygon.
    Markus

  • Has anyone tried to update using the direct download file of 4.2.1?

    My internet connection isn't the fastest at home so I downloaded the update file at my office using the following link :
    http://appldnld.apple.com/iPad/061-9857.20101122.VGthy/iPad1,14.2.1_8C148Restore.ipsw
    Any tips on how to proceed with doing the update using this file? I know you have to Option-Click the Update or Restore button, and then browse to the update file, but I was wondering if there is anything else I should do first.

    Thanks to both of you - I was running 4.2 on my iPad, and the download link at daw.apple.com for the 4.2.1 GM was taken down after it shipped - so I was bummed...
    Found your post with the direct download link - boom! Happy camper...
    Aaron

Maybe you are looking for

  • Zen Touch latest Firmware Update...player not connec

    I tried installing the latest Firmware update for my Zen Touch (released 2-09). The player is connected and recognized by Windows and the Media Explorer. However, when I try to install the new Firmware it keeps saying "player not connected". I tried

  • Bug in inline view

    Hi, Here is a reproducible bug I just meet. I tried it on 9.2.0.5 and 10.1.0.2 (AIX). the "select *" generates duplicates ! Regards Laurent Schneider OCM DBA SQL> select * from ( select distinct deptno from ( select deptno, job, min(sal) from scott.e

  • Software Update doesn't work---- PLEASE HELP!!!

    Hello, My software update dosent work. It has worked in the past, but one day it just stopped working... it returnes with an error saying "Sorry, an unexpected error occurred. The Installer package has been moved to the Trash. To try again, open the

  • IPhoto 11 Share to Facebook is Broken

    Since last week, every time I try to share anything with Facebook I get a blank album even though iPhoto goes through the full upload process. I have tried the following: Remove iPhoto app settings from Facebook Remove Facebook account from iPhoto Re

  • Migrating DHCP Server From OpenSuse to Windows Server 2008 R2 Standard

    Hello, I'm planning to migrate a DHCP server from OpenSuse to Windows Server 2008. Is there any procedures for that ,Or should i configure my Windows server 2008 DHCP service again. Thank you