Finding generated keys with batch updates

Is it possible to combine reading generated keys with batch updates?
In trying to improve performance of inserts into a database, I am using the addBatch functionality of the JDBC driver to insert several rows at once. Unfortunately some of my tables have auto numbered fields and I need to know what values they are taking so I can update my in-memory representation of the object in the database.
The getGeneratedKeys functionality works fine when I insert one row at a time, but when I try to insert a batch of rows, the method returns null.
I am using DB2 with the com.ibm.db2.jcc driver, though I have a hunch that this is a limitation of the JDBC spec. Can anyone confirm this? Does anyone have any ideas about a workaround?

What is "several"?
And have you actually measured the speed difference?
Since returning generated keys is a rather recent addition to JDBC I doubt that it exists for batch updates.

Similar Messages

  • HELP!!! Strange Error with Batch Update

    While trying to do a batch update with the following preparedstatment:
    INSERT INTO TAB1
    (DATETIME,CALC_ID,SITE_ID,APPL_ID,VAL)
    values (
    {ts '2003-06-24 08:49:14'},
    (SELECT CALC_ID FROM TAB2 WHERE CALC_NAME=?),
    2,
    7,
    Notice the parameter in the subquery. This works fine for a single executeUpdate. But if i do two preparedstatement.addbatch calls and then executeBatch I see a unique constraint violation on (DATETIME,CALC_ID, and SITE_ID) CALC_ID is the only key that varies in my batch. It is as if the subquery is not being resolved and written literally to the field. If I try the 1st update by itself in add batch it works. If I try the second it works by itself. If I try them together in the batch it fails. The unique constraint is not violated when I execute them singly.
    Any Ideas?
    Thanks in advance.

    I've found that db2, PreparedStatements and batch updating do not work very well together. I've had to use dynmanic sql and build the update statement myself. Actually I wrote a query parser that builds the statement so I can pass it like a PreparedStatement.
    I'm not sure if your in db2 ver 7 but if so make sure your using fixpack 9. at lot of bad prepared statement behavior.

  • Problem with Batch Updates

    Hi All,
    I have a requirement where in I have to use batch updates. But if there's a problem in one of the updates, I want the rest of the updates to ingore this and continue with the next statement in the batch. Is this not one of the features in BatchUpdates in JDBC2? I have been trying to accomplish this since 2 days now. Can anyone help me with this. Can anyone please help me with this?
    FYI, I have tried the following.
    I have 3 test updates in my batch.
    2 nd statement is an erraneous statement(deliberate). Other 2 statements are fine. It is appropriatley throwing 'BatchUpdateException'. when I ckeck the "arrays of ints" reurned by executeBatch() as well as BatchUpdateException.getUpdateCounts() are returning an arrays of size '0'. If remeove the erraneous statement, behaviour is as expected.
    Thanks in advance,
    Bharani

    The next paragraph of the same API doc:
    If the driver continues processing after a failure, the array returned by the method BatchUpdateException.getUpdateCounts will contain as many elements as there are commands in the batch, and at least one of the elements will be the following:
    3. A value of -3 -- indicates that the command failed to execute successfully and occurs only if a driver continues to process commands after a command fails
    A driver is not required to implement this method.

  • Failure to generate key with keytool

    I tried to use keytool to generate a key on Linux. It was successful on other Linux machines, but it is strange that it is failure on my production server.
    # /usr/java/jdk/bin/keytool -genkey -v -alias test2 -keyalg RSA
    Enter keystore password: changeit
    What is your first and last name?
    [Unknown]:
    What is the name of your organizational unit?
    [Unknown]:
    What is the name of your organization?
    [Unknown]:
    What is the name of your City or Locality?
    [Unknown]:
    What is the name of your State or Province?
    [Unknown]:
    What is the two-letter country code for this unit?
    [Unknown]:
    Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
    [no]: yes
    Generating 1,024 bit RSA key pair and self-signed certificate (MD5WithRSA)
    for: CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown
    And then the keytool keeps running but cannot generate a key.
    My production server is:
    - Intel Pentinum III 850 with 256MB RAM
    - RedHat Linux 7.2
    - Java 2 SDK build 1.4.0-beta3-b84
    Remark: I tried with same version of Linux distro and Java SDK on other machine, but it was successful.

    Chances are it is hung on the SecureRandom's use of the /dev/random
    device. If I recall right the proper /dev/random on linux is really
    /dev/urandom. So what you need to do is edit the
    <java_home>/jre/lib/security/java.security file a change the property
    to /dev/urandom instead of its default /dev/random value.....

  • Problem generating Key  with keytool command

    Hi Everyone;
    I'm having problems generating a key.
    Here's my output.
    C:\>keytool -genkey -alias learningIdeas -keysize 1024 -validity 365 -keyalg RSA
    Enter keystore password: changeit
    keytool error: java.io.IOException: Keystore was tampered with, or password was incorrect
    note i already did something with the keystore such that i have generated a key and placed this in server.xml
    <Connector className="org.apache.tomcat.service.PoolTcpConnector">
    <Parameter name="handler" value="org.apache.tomcat.service.http.HttpConnectionHandler"/>
    <Parameter name="port" value="8443"/>
    <Parameter name="socketFactory" value="org.apache.tomcat.net.SSLSocketFactory" />
         <Parameter name="keystore" value="C:/stephen" />
         <Parameter name="keypass" value="changeit"/>
         <Parameter name="clientAuth" value="false"/>
    </Connector>
    any ideas on what I can do to generate this key?
    stephen

    I have almost resolved this problem. I'm at the last step and getting an error message when trying to import the certificate that I received from verisign into my keystore.
    here's my error.
    C:\>keytool -import -alias mycompanyname123 -keystore STEPHEN4 -file mycompanyname.cer
    Enter keystore password: changeit
    keytool error: java.security.cert.CertificateException: Unsupported encoding
    but when I double click on this file mycompanyname.cer (which is exactly what I received from verisign, up comes the appropriate certificate
    i was able to succesfully able to install it into the microsoft browser and i see it correctly represented and displayed in the certificates section for OTHER PEOPLE.
    But I think i have to successfully import it into the keystore for it to work properly right when I start up the tomcaat app is that correct?
    any ideas?
    Stephen

  • SNRO generate key with SM30

    I have a Ztable where I want to use an unique index key which I have maintained by SNRO.
    Is it possible to combine this with the data maintenance in SM30 so that I don't have to fill in the key myself but that it just takes the next one if I want to add a new record with SM30 ??
    (ps perhaps a really stupid question but I can't figure out how I can search on SNRO AND SM30 in sdn ? so it was impossible for me to find if this question was already asked before how can you use the "and" function in sdn ? )

    Hi,
    Try this..
    You can use the event 05 "Creating a new entry" and in the subroutine you can call NUMBER_GET_NEXT to get the next number and move it to the key field...
    Check this example..
    Create an entry in the view TVIMF with your table name..event 05 and subroutine GET_NUMBER_NEXT.
    FORM GET_NUMBER_NEXT.
    Types Declaration
      TYPES: BEGIN OF ztable_wa.
              INCLUDE STRUCTURE ztable.
      TYPES:  update_fl TYPE char1,
              mark      TYPE char1,
             END OF ztable_wa.
    Workarea Declaration
      DATA: wa TYPE ztable_wa.
    Assign the current workarea
        wa = <table1>.
    Call the function module
       CALL FUNCTION 'NUMBER_GET_NEXT'
    Assign the value.
        wa-key_field1 = 'Value got from the FM'.
    ENDFORM.
    Thanks,
    Naren

  • License key check and update

    Hi
    We have Exchange 2010 Servers in our environment and Team is not sure about the License key used.
    Is there anyway to check which license key is currently used ?
    How to change the License key with new/updated key if there areany such changes due to aquisation, merging etc.
    Pls help
    Regards:Mahesh

    Hi,
    I am afraid it’s not possible. If you bought the key directly from Microsoft, please contact the customer service.
    If you bought it from third-party vendor, please call the third-party for assistance.
    Thanks,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Simon Wu
    TechNet Community Support

  • [ME21] error message : cannot find message associated with key

    Dear all,
    I try to develop an Mobile application using smartSync,
    but when the application running (on client) got an error message :
    Error: 500
    Location: /UPLOAD_TEST/upload_testapp/Menu.do
    Internal Servlet Error:
    javax.servlet.ServletException: cannot find message associated with key : dispatcher.forwardException
    at org.apache.tomcat.facade.RequestDispatcherImpl.doForward(RequestDispatcherImpl.java:238)
    at org.apache.tomcat.facade.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:162)
    at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:423)
    at 0002findex0002ejspindex_jsp_0._jspService(_0002findex_0002ejspindex_jsp_0.java:62)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java)
    note:
    when create this application, I'm using tcode : merep_sbuilder
    Sync type : U01 - Upload using SMAPIs
    Bapi wrapper : MEREP_CONTACT_CREATE
    SAP Mobile Engine 2.1
    and generate .war file using MDK tool
    any one know about this ??
    thanks & regards,

    Hi,
    this error comes up when the destination serlvet throws an exception other than ServletException!
    Its a standard tomcat bug!
    Rgds Thomas
    -->
    http://issues.apache.org/bugzilla/show_bug.cgi?id=19114
    -->From apache.org:
    When a forwarded servlet throws an exception other than ServletException or
    IOException, the thrown exception is lost. This is due to the line:
    throw new ServletException(sm.getString("dispatcher.forwardException", t));
    (found in org/apache/tomcat/facade/RequestDispatcherImpl.java:210)
    the earlier catched t is here not passed into the constructor of
    ServletException but into getString.
    To reproduce construct a servlet that throws an Exception (other than
    ServletException and IOException) and another servlet that forwards to it. You
    will get just a forwardException (if you have the proper locale strings
    installed!) but the originally thrown exception will get lost forever.

  • No major shortcomings keyboard arrow key. even if the text part of the message you clicked the arrow keys to update the screen would be great. with an update on my idea, and so it would be more useful

    no major shortcomings keyboard arrow key. even if the text part of the message you clicked the arrow keys to update the screen would be great. with an update on my idea, and so it would be more useful

    greghcrash wrote:
    It Would be great to have keys on the onscreen keyboard.
    Such as a computer keyboard.
    With BACKSPACE, TAB WITH SETTINGS, DELETE, TYPE OF TYPE, BOLD TYPE, UNDERLINE ETC....
    I HAVE A KEYBOARD COVER AND IF I NEED TO USE CERTAIN KEYS I HAVE TO SWITCH TO MY KEYBOARD CASE AND THAT IS VERY INCONVENIENT.
    IT IS ALSO A TIME WASTER.
    When you installed iOS 8 did you read about the new features? Applications can create custom keyboards…
    http://www.imore.com/custom-keyboards-ios-8-explained
    You need to look for an app that has a custom keyboard with the features you require, I suggest you find one without CAPSLOCK
    greghcrash wrote:
    IT IS ALSO AGGRAVATING WHEN TYPING AND IT AUTOMATICALLY CHANGES THE WORDS THAT YOU WANT TO USE.
    THANK YOU FOR YOUR TIME
    Again you need to look at how to manage the device - these settings can be turned off already & you can edit the 'suggestions' too.
    Settings > General > Keyboards > turn Auto-Correction Off.
    Sadly you cannot disable autocorrect temporarily, so it's all or nothing.

  • CF 9.0.2 and Oracle - On update returns error "Auto-generated keys were not requested..."

    We have a simple update statement to Oracle 11g Database. When running the statement the data is not getting updated and we are getting an error "Auto-generated keys were not requested, or the SQL was not a simple INSERT statement. ErrorCode=0 SQLState=HY000". We found this error by dumping the SQL to a file.
    But most other Update statements are working fine.
    Also, the same statment works for Oracle 10g and Coldfusion 9.0.0.
    Any idea if this is a problem with Coldfusion or Oracle? Is there any resolution.
    I found the CF 8 had a similar issue and was fixed in a hotfix (http://helpx.adobe.com/coldfusion/kb/error-auto-generated-keys-requested.html).

    Hi,
    Thanks. I compiled my code using JDeveloper 10.1.2, didn't dare to use the latest. It works in 10g apps server. When I deployed to 9ias apps server, those weird errors showed up. Unfornately, our dev environment is at a newer version than the production one.
    So, you think the error is generated because I referenced some newer technologies that was not provided by 9ias?
    Jia

  • How Can I install Framemaker 10 silently with serial key and license updater?

    How Can I install Framemaker 10 silently with serial key and license updater? Is there any tool to create MSI for this?
    I tried with using http://download.macromedia.com/pub/developer/creativesuite/AAMEE/win32/ApplicationManagerE nterprise_1_all.exe and its not supporting.
    I am looking for any customization tool for Framemaker 10 from Adobe or else silent install with serial and license updater

    After creating "application.xml.override" from above link
    First after installing manually Adobe Framemaker 10,Copy "pcd.db" to your source folder from "%ProgramFiles(x86)%\Common Files\Adobe\Adobe PCD\" once you run "LicenseUpdater.exe"
    1) For install create batch file "install.bat" and copy below command
    @echo off
    REM =====Install script=====
    set Current=%~dp0
    "%Current%Set-up.exe" --mode=silent --deploymentFile="%Current%\deploy\AdobeFrameMaker10_en_US.install.xml" --overrideFile="%Current%\deploy\application.xml.override" --acton=install
    COPY /Y "%Current%pcd.db" "%ProgramFiles(x86)%\Common Files\Adobe\Adobe PCD\pcd.db"
    Exit 0
    2) For Uninstall
    * download Adobeairinstaller from Adobe - Adobe AIR to uninstall adobe AIR silently and copy this exe in source folder
    Create batch file to uninstall Framemaker 10 "Uninstall.bat" and copy below command to Uninstall
    @echo off
    REM =====Uninstall script=====
    set Current=%~dp0
    REM Uninstalling "Adobe Framemaker 10"
    "%Current%Set-up.exe" --mode=silent --deploymentFile="%Current%\deploy\AdobeFrameMaker10_en_US.remove.xml" --overrideFile="%Current%\deploy\application.xml.override" --acton=uninstall
    DEL /F /Q "%ProgramFiles(x86)%\Common Files\Adobe\Adobe PCD\pcd.db"
    REM Uninstalling Adobe community help
    msiexec /x {E2B04924-29F3-F49D-71E9-B90EFEDE282C} /qn
    REM Uninstalling Adobe PDF creation Add-On 9
    msiexec /x {AC76D478-1033-0000-3478-000000000004} /qn
    REM Uninstalling Adobe AIR
    "%Current%AdobeAIRInstaller.exe" -uninstall
    Exit 0
    I think this will help....

  • Report generated through BIP Server not in sync with data updated in DB

    Hi,
    We have an issue where the BIP report show up the old value instead of the latest updated & commited value done from Application(ADF) on the same session or transaction.
    Does BIP have any caching mechanism implemented internally for a user context?
    Detailed Explanation :
    After verifying several scenarios, following are the scenarios which reproduced the cache issue in our application:
    Case -1:
    1) Logged in as user "User1".
    2) Navigated to page where we can update data and we have option to print/generate the report.
    3) Now made some updates in the page and saved it.
    4) Now generate the report, report is generated with the updated information.
    5) Now close the report generated and update the page with some other modifications and save it.
    6) Now generate the report, but the report doesn't have the updated info.
    Case-2:
    1) Logged in as user "User2".
    2) Navigated to page where we can update data and we have option to print/generate the report.
    3) Generate the print profile report, you see the changes made above with "User1" login.
    4) Now close the report generated and update the page with some more modifications and save it.
    5) Now generate the report, but the report doesn't have the updated info.
    Seems like, the request sent to BIP server is being cached at BIP server with its response considering the key with following format:
    <Login User-id> + <Request Parameters> .
    We are thinking this way because, in both Case-1 and Case-2, if we are modifying the request parameters values (fields to be shown in the generated report) uniquely for each new request,
    then we are seeing the changes updated in DB are present in the report generated.
    Can someone give inputs, how to overcome this issue?
    Thanks,
    Kiran Kumar

    if you are using the cold backup to create the standby database, Check that have you followed the following steps or not.
    1. remove
    all the datafiles and controlfiles from the standby database.
    2. Create a new standby controlfile of the production for standby using the following cmd
    'alter database create standby controlfile as 'Location';'
    3. move the new controlfile to standby database server location as specified in initialization parameter file.
    4. Restore all the datafiles to its appropriate loaction which was taken through cold backup.
    5. startup nomount
    6. alter database mount standby database;
    7. recover standby database.
    scp the archive log sequence that is asked by the database, from production.
    You can try this steps.

  • Batch updates with callable/prepared statement?

    The document http://edocs.bea.com/wls/docs70/oracle/advanced.html#1158797 states
    that "Using Batch updates with the callableStatement or preparedStatement is
    not supported". What does that actually mean? We have used both callable and prepared
    statements with the batch update in our current project (with the Oracle 817 db).
    It seems to run ok anyway.

    So the documentation should state that batch updates do not work ok in old versions
    of JDriver for Oracle, BUT work correctly with newer version. Additionally, batch
    updates work ok when used with Oracle supplied jdbc-drivers?
    "Stephen Felts" <[email protected]> wrote:
    Support for addBatch and executeBatch in the WLS Jdriver for Oracle was
    added in 7.0SP2.
    It was not available in 6.X or 7.0 or 7.0SP1.
    "Janne" <[email protected]> wrote in message news:3edb0cdc$[email protected]..
    The document http://edocs.bea.com/wls/docs70/oracle/advanced.html#1158797
    states
    that "Using Batch updates with the callableStatement or preparedStatementis
    not supported". What does that actually mean? We have used both callableand prepared
    statements with the batch update in our current project (with the Oracle817 db).
    It seems to run ok anyway.

  • ON UPDATE CASCADE and Autoincrement primary key with Oracle SQL Developer

    hello everybody,
    I want to know if Oracle SQL Developer manage autoincrement on primary key and "ON UPDATE CASCADE" when i migrate (with data) SQL Server database in Oracle database.
    Can you help me ?
    Thanks for your suggestions.

    Obtain the value of the auto increment key with the getGeneratedKeys() method.
    Statement stmt = null;
    ResultSet rs = null;
    stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
                                    java.sql.ResultSet.CONCUR_UPDATABLE);
    stmt.executeUpdate("DROP TABLE IF EXISTS autoIncTable");
        stmt.executeUpdate(
                "CREATE TABLE autoIncTable ("
                + "priKey INT NOT NULL AUTO_INCREMENT, "
                + "dataField VARCHAR(64), PRIMARY KEY (priKey))");
    stmt.executeUpdate(
                "INSERT INTO autoIncTable  (dataField) "
                + "values ('data field value')",
                Statement.RETURN_GENERATED_KEYS);
    int autoIncKeyFromApi = -1;
        rs = stmt.getGeneratedKeys();
        if (rs.next()) {
            autoIncKeyFromApi = rs.getInt(1);
        } else {
        rs.close();

  • SyncBo Example - cannot find message associated with key

    Hi,
    I followed the tuturial to create a SmartSync Project.
    And when I run the project I've got a Servlet Exception:
    javax.servlet.ServletException: cannot find message appropriated with key: dispatcher.forwardException.
    What I need to change?
    Thanks a lot,
    Rachid

    Hi,
    this error comes up when the destination serlvet throws an exception other than ServletException!
    Its a standard tomcat bug!
    Rgds Thomas
    -->
    http://issues.apache.org/bugzilla/show_bug.cgi?id=19114
    -->From apache.org:
    When a forwarded servlet throws an exception other than ServletException or
    IOException, the thrown exception is lost. This is due to the line:
    throw new ServletException(sm.getString("dispatcher.forwardException", t));
    (found in org/apache/tomcat/facade/RequestDispatcherImpl.java:210)
    the earlier catched t is here not passed into the constructor of
    ServletException but into getString.
    To reproduce construct a servlet that throws an Exception (other than
    ServletException and IOException) and another servlet that forwards to it. You
    will get just a forwardException (if you have the proper locale strings
    installed!) but the originally thrown exception will get lost forever.

Maybe you are looking for