Insert - database

Hello All...I have a question ...When we insert a record into the database using jdbc and if that record cannot be inserted as it violates primary key / duplicate key and throws an exception...how can we handle such situation ...do we need to show the user that the record cannot be inserted as it already exists in the database...and if yes how to check it
help is greatly appreciated...
Thansk,
Greeshma

The Connection object has a method, setAutoCommit() and a property autoCommit.
con.setAutoCommit(false);would set turn off auto commit. So all data would be entered into the database, but not committed. If you think everything is ok, you would call,
con.commit();else, in case exceptions are thrown, call,
con.rollback();j
This basically allows you to make transactions on the database and rollback if it fails.
By the way, you should turn on auto commit once you finish with your transaction so that at other places, you do not accidently use a connection that you will need to explicitly call commit() on.
Your code should be something like this:
try
    con.setAutoCommit(false);
    try
        //execute your preparedstatement
        //once you're done, i.e after your loop or whatever and you're sure you've entered all data, commit
        con.commit();
    catch ( Exception e )
        con.rollback(); //undo whatever inserts may have happened
catch ( Exception e )
    System.out.println("Unable to turn off auto-commit: " + e );
finally
    //try to put autocommit back on
    try
        con.setAutoCommit(true);
       //not sure but I think an exception is thrown if it is already true
    catch ( Exception e )
        System.out.println("Failed to turn on autocommit: " + e );
}

Similar Messages

  • How can I create a "Next" button with Insert database action

    Hello,
         I want to create a "Next" button that will redirect to another page and at the same time to do an INSERT database action. I've searched on google but I didn't find nothing specific that could help me.
    Below are some screenshots:
    http://imagizer.imageshack.us/v2/800x600q90/22/2yqj.jpg
    http://imagizer.imageshack.us/v2/800x600q90/585/wbn6.jpg
         Thanks.

    DO NOT USE THIS CODE !!!!
    Declare 
      -- Added by ramani 20-feb-2013 
       Seq_Val_ Number; 
    begin 
        if  :P17_NWM_DOC_NO  is null  then 
           Select Nvl(count(NWM_DOC_NO),0) + 1  -- THIS IS VERY VERY WRONG !!! REPLACE WITH A SEQUENCE !!!!!!!!!!!!!!
            into Seq_Val_ 
            from  DMS_NEW_MASTER; 
           -- ref number 
            return  Seq_Val_ ; 
            --summa oru elsif irukku 
           end if;  
    end; 

  • Insert Database Name onto Report

    I would like to Insert Database Name into Header of Report. Presently Using Crystal Reports 2008 and SQL Express, but will be migrating to Postgres.
    Thanks in advance.

    If you're using SQLExpress (or any version of MS SQL) and tables/views as your datasource, you could use a "SQL Expression Field" in Crystal.  Just create one (it's over there by your formulas!) and it's real simple:
    db_name()
    and drop it onto your page.
    If you're using commandtext as your datasource, just add the above into your select statement...
    select
    db_name() as ThisIsMyDatabaseName,
    someval,
    anotherval
    from MyTable
    No idea about Postgres, but I'd be stunned if it didn't have a similar function to return the current database name.

  • How to insert database elements?

    Hi all,
    could you please tell me .. how to add insert command in our abap program to insert the database elements?  and also we want to know whether we can add the same insert statement we are using on the oracle.we tried with that command but it cause some problem.
    INSERT INTO ZJEYC1 VALUES (' & CUSTNO ' , ' & CUSTNAME & ' , ' & CUSTADDRESS & ' , ' & CUSTMOB & ').
    is it correct?...
    if no please send me the code...

    INSERT - Insert in a database table
    Variants
    1. INSERT INTO dbtab VALUES wa. or
    INSERT INTO (dbtabname) VALUES wa.
    2. INSERT dbtab. or
    INSERT *dbtab. or
    INSERT (dbtabname) ...
    3. INSERT dbtab FROM TABLE itab. or
    INSERT (dbtabname) FROM TABLE itab.
    Effect
    Inserts new lines in a database table .
    You can specify the name of the database table either in the program itself in the form dbtab or at runtime as the contents of the field dbtabname . In both cases, the database table must be defined in the ABAP/4 Dictionary . If the program contains the name of the database table, it must also include a corresponding TABLES statement. Normally, lines are inserted only in the current client. Data can only be inserted using a view if the view refers to a single table and was defined in the ABAP/4 Dictionary with the maintenance status "No restriction".
    INSERT belongs to the Open SQL command set.
    Notes
    You cannot insert a line if a line with the same primary key already exists or if a UNIQUE index already has a line with identical key field values.
    When inserting lines using a view , all fields of the database table that are not in the view are set to their initial value (see TABLES ) - if they were defined with NOT NULL in the ABAP/4 Dictionary . Otherwise they are set to NULL .
    Since the INSERT statement does not perform authorization checks , you must program these yourself.
    Lines specified in the INSERT command are not actually added to the database table until after the next ROLLBACK WORK . Lines added within a transaction remain locked until the transaction has finished. The end of a transaction is either a COMMIT WORK , where all database changes performed within the transaction are made irrevocable, or a ROLLBACK WORK , which cancels all database changes performed within the transaction.
    Variant 1
    INSERT INTO dbtab VALUES wa. or
    INSERT INTO (dbtabname) VALUES wa.
    Addition
    ... CLIENT SPECIFIED
    Effect
    Inserts one line into a database table.
    The line to be inserted is taken from the work area wa and the data read from left to right according to the structure of the table work area dbtab (see TABLES ). Here, the structure of wa is not taken into account. For this reason, the work area wa must be at least as wide (see DATA ) as the table work area dbtab and the alignment of the work area wa must correspond to the alignment of the table work area. Otherwise, a runtime error occurs.
    When the command has been executed, the system field SY-DBCNT contains the number of inserted lines (0 or 1).
    The return code value is set as follows:
    SY-SUBRC = 0 Line was successfully inserted.
    SY_SUBRC = 4 Line could not be inserted since a line with the same key already exists.
    Example
    Insert the customer Robinson in the current client:
        TABLES SCUSTOM.
        SCUSTOM-ID        = '12400177'.
        SCUSTOM-NAME      = 'Robinson'.
        SCUSTOM-POSTCODE  = '69542'.
        SCUSTOM-CITY      = 'Heidelberg'.
        SCUSTOM-CUSTTYPE  = 'P'.
        SCUSTOM-DISCOUNT  = '003'.
        SCUSTOM-TELEPHONE = '06201/44889'.
        INSERT INTO SCUSTOM VALUES SCUSTOM.
    Addition
    ... CLIENT SPECIFIED
    Effect
    Switches off automatic client handling. This allows you to insert data across all clients even when dealing with client-specific tables. The client field is then treated like a normal table field which you can program to accept values in the work area wa that contains the line to be inserted.
    The addition CLIENT SPECIFIED must be specified immediately after the name of the database table.
    Example
    Insert the customer Robinson in client 2:
        TABLES SCUSTOM.
        SCUSTOM-MANDT     = '002'.
        SCUSTOM-ID        = '12400177'.
        SCUSTOM-NAME      = 'Robinson'.
        SCUSTOM-POSTCODE  = '69542'.
        SCUSTOM-CITY      = 'Heidelberg'.
        SCUSTOM-CUSTTYPE  = 'P'.
        SCUSTOM-DISCOUNT  = '003'.
        SCUSTOM-TELEPHONE = '06201/44889'.
        INSERT INTO SCUSTOM CLIENT SPECIFIED VALUES SCUSTOM.
    Variant 2
    INSERT dbtab. or
    INSERT *dbtab. or
    INSERT (dbtabname) ...
    Additions
    1. ... FROM wa
    2. ... CLIENT SPECIFIED
    Effect
    These are the SAP -specific short forms for the statements explained under variant 1.
    INSERT INTO dbtab VALUES dbtab. or
    INSERT INTO dbtab VALUES *dbtab. or
    INSERT INTO (dbtabname) VALUES wa.
    When the command has been executed, the system field SY-DBCNT contains the number of inserted lines (0 or 1).
    The return code value is set as follows:
    SY-SUBRC = 0 Line successfully inserted.
    SY_SUBRC = 4 Line could not be inserted, since a line with the same key already exists.
    Example
    Add a line to a database table:
        TABLES SAIRPORT.
        SAIRPORT-ID   = 'NEW'.
        SAIRPORT-NAME = 'NEWPORT APT'.
        INSERT SAIRPORT.
    Addition 1
    ... FROM wa
    Effect
    The values for the line to be inserted are not taken from the table work area dbtab , but from the explicitly specified work area wa . The work area wa must also satisfy the conditions described in variant 1. As with this variant, the addition allows you to specify the name of the database table directly or indirectly.
    Note
    If a work area is not explicitly specified, the values for the line to be inserted are taken from the table work area dbtab if the statement is in a FORM or FUNCTION where the table work area is stored in a formal parameter or local variable of the same name.
    Addition 2
    ... CLIENT SPECIFIED
    Effect
    As for variant 1.
    Variant 3
    INSERT dbtab FROM TABLE itab. or
    INSERT (dbtabname) FROM TABLE itab.
    Additions
    ... CLIENT SPECIFIED
    ... ACCEPTING DUPLICATE KEYS
    Effect
    Mass insert: Inserzts all lines of the internal table itab in a single operation. The lines of itab must satisfy the same conditions as the work area wa in variant 1.
    When the command has been executed, the system field SY-DBCNT contains the number of inserted lines.
    The return code value is set as follows:
    SY-SUBRC = 0 All lines successfully inserted. Any other result causes a runtime error .
    Note
    If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0 after the call.
    Addition 1
    ... CLIENT SPECIFIED
    Effect
    As for variant 1.
    Addition 2
    ... ACCEPTING DUPLICATE KEYS
    Effect
    If a line cannot be inserted, the processing does not terminate with a runtime error, but the return code value of SY-SUBRC is merely set to 4. All the remaining lines are inserted when the command is executed.
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • Updating or inserting database problem

    Hi,
    I have a problem when i try to insert or update records within database from java, i m using ms access.
    I can retrive the data from the table but when i insert or update it , the code executes without any error but has no effect on the table.
    I would be thankful if u guyz help me out .
    The code is below :
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//loading drivers
              Connection conn = DriverManager.getConnection("jdbc:odbc:client");
              Statement s = conn.createStatement();
              ResultSet rs = s.executeQuery("insert into client (name,hours,minutes) values ('ik',2,34)");
         /*     int c = s.executeUpdate("insert into client (name,hours,minutes) values ('ik',2,34)");
              rs.absolute(2);
              rs.updateString("Name","dla");
              rs = s.executeQuery("commit");*/
    rs.close();
    s.close();
    conn.close();

    Thanks for reply, i appreciate the help u guyz hav givin me
    they wer helpful upto some extent but the actual problem with
    my coding was that statment s variable is used with to different
    sql queries ,
    when i used s variable with a single query the base table was affected with the coding changes.
    Thanks once again guyz....!

  • Parameter insert database connectivity

    I'm currently having a little trouble getting this to work.  Below is a picture of my block diagram, it includes pretty much everything there is to know about my error. As you can see it says it has a syntax error. I'm fairly new to labVIEW but I do quite a bit of database programming. The insert statments looks correct. I would assume the error lies within the values passed into the parameters. I've tried it both with and without single quotes around the values. I would also like to note that the 2 int32 convertsion were thrown in after the error was already there. Was just running out of ideas to try. Incase you can't recognize the VI. We have an open database vi -> parameterized query -> 2 set parameters -> exec query-> free object-> free conn-> close conn. This is the exact same layout for the database connections as is in the database connectivity manual. I've already tested the connection to the database inserting a single value and that worked. For some reason now that I'm spliting the values coming out of the DAQ assistant and made it a parameterized query, it is no longer working. Any help would be great. Thanks.

    [As far as the special characters in the insert
    string I wouldn't believe there would be any unless they some how get
    added automatically. If they are is that a common issue? ]
    I was just making sure human error didn't creep in when the INSERT string was created. It's bit me more than once.
    Have you tried hard coding some Voltage and Current values into the Set Parameter Value VI's? You might also try setting the "auto-detect parameters" in the Create Parameterized Query VI to TRUE and disconnecting the Parameters array constant. Also, check the string "Current" in the Parameter constant array (index 1), make sure there's no space at the end of the name.
    “A child of five could understand this. Send someone to fetch a child of five.”
    ― Groucho Marx

  • How can I make a 'Rollback Point' when I Insert database.

    desiring on edge!

    Hi Steven,
    just to clarify everything done in one dbadapter invoke uses a single atomic database transaction.
    We have no support right now for the jdbc 'savepoint' feature, but from your explanation it seems you want the dbadapter write to be rolled back if the bpel process itself fails.
    There is a way to do this, by configuring the dbadapter to bind its transaction to the global bpel instance transaction.
    This JTAInsert is not shipped with the ga samples but here is the README:
    This is an advanced sample.
    Follow the steps to create the Merge sample, but then add a second duplicate
    merge invoke.
    Attempting to do two duplicate merges of the same object will lead to the
    following:
    -If the row (title) exists then two duplicate updates will be made.
    -If the row (title) does not exist then two inserts will be attempted. The
    second insert will fail, causing the first insert to be rolled back aswell.
    The only other difference is to add the following adapter instance to your
    oc4j-ra.xml and use it instead of eis/DB/BPELSamples:
         <connector-factory location="eis/DB/BPELSamplesDataSource" connector-name="Database Adapter">
              <config-property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
              <config-property name="connectionString" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
              <config-property name="userName" value="system"/>
              <config-property name="password" value="any"/>
              <config-property name="minConnections" value="5"/>
              <config-property name="maxConnections" value="5"/>
              <config-property name="minReadConnections" value="1"/>
              <config-property name="maxReadConnections" value="1"/>
              <config-property name="usesExternalConnectionPooling" value="true"/>
              <config-property name="dataSourceName" value="jdbc/BPELSamplesDataSource"/>
              <config-property name="usesExternalTransactionController" value="true"/>
              <config-property name="platformClassName" value="oracle.toplink.internal.databaseaccess.Oracle9Platform"/>
              <config-property name="usesNativeSequencing" value="true"/>
              <config-property name="sequencePreallocationSize" value="50"/>
              <config-property name="tableQualifier" value=""/>
         </connector-factory>
    Notice the following key properties are set:
              <config-property name="usesExternalConnectionPooling" value="true"/>
              <config-property name="dataSourceName" value="jdbc/BPELSamplesDataSource"/>
              <config-property name="usesExternalTransactionController" value="true"/>
    Issues:
    This works only for "Merge" operation. "Insert" operation does not.
    When you run this and chose a new title, the first insert is rolled back correctly
    but then the instance does not appear in the bpel console. Likely because the dehydration/auditing is also rolled back.
    Looking for it resulted in:
    <2005-05-25 15:16:24,518> <ERROR> <default.collaxa.cube> <BaseCubeSessionBean::l
    ogError> Error while invoking bean "finder": Instance not found in datasource.
    The process domain was unable to fetch the instance with key "17da72ea26ff041b:d
    09ad3:10410ffa8e2:-7fe6" from the datasource.
    Please check that the instance key "17da72ea26ff041b:d09ad3:10410ffa8e2:-7fe6" r
    efers to a valid instance that has been started and not removed from the process
    domain.
    To verify:
    run polsql @122.DBAdapter/sql/setup.sql first
    then run polslq and
    select title from movies;
    The title you inserted should not appear if the first insert was rolled back.
    Thanks
    Steve

  • How to insert database view in workspace

    Hi,
    I am very new to Universe Designer. I am trying to insert DB VIEWS in workspace using Table Browser; however, I only see TABLES.
    Some data in our Oracle repository is only availabe in VIEWS. The VIEWS data are coming from some datasources and they are not available in the repository's TABLES.
    Could anyone help me ?
    Thank you,
    Sri

    Hi,
    Views are listed with tables. There is no difference between voiew and tables in Universe Designer.
    So do you have rights to see those views? If you are not the owner of the views, do you know if synonyms have been created on those views?
    Regards
    Didier

  • Insert database problem

    i have got this error
    Error inserting valuejava.sql.SQLException: General error
    dring inserting record in databse
    here is my code
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import java.util.Date;
    import java.lang.String;
    public class sign extends HttpServlet
    public void doPost(HttpServletRequest request,HttpServletResponse res) throws ServletException,IOException
    Connection conn;
    conn=null;
    ResultSet rs,rs1;
    res.setContentType("text/html");
    PrintWriter out =res.getWriter();
    rs=null;
    String UserName=request.getParameter("UserName");
    String Password=request.getParameter("Password");
    String Password2=request.getParameter("Password2");
    String prn=request.getParameter("prn");
    String FirstName=request.getParameter("FirstName");
    String MiddleName=request.getParameter("MiddleName");
    String LastName=request.getParameter("LastName");
    String Address1=request.getParameter("Address1");
    String City=request.getParameter("City");
    String Phone=request.getParameter("Phone");
    String Email=request.getParameter("Email");
    String CName=request.getParameter("CName");
    String Year=request.getParameter("Year");
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn =DriverManager.getConnection("jdbc:odbc:mydsn");
    PreparedStatement stat1=conn.prepareStatement("INSERT INTO login values(?,?)");
    stat1.setString(1,UserName);
    stat1.setString(2,Password);
    PreparedStatement stat=conn.prepareStatement("INSERT INTO student values(?,?,?,?,?,?,?,?,?,?,?,?)");
    stat.setString(1,UserName);
    stat.setString(2,Password);
    stat.setString(3,prn);
    stat.setString(4,FirstName);
    stat.setString(5,MiddleName);
    stat.setString(6,LastName);
    stat.setString(7,Address1);
    stat.setString(8,City);
    stat.setString(9,Email);
    stat.setString(10,Phone);
    stat.setString(11,CName);
    stat.setString(12,Year);
    stat.executeUpdate();
    stat1.executeUpdate();
    rs.close();
    conn.close();
    catch(Exception E)
    out.println("Error inserting value"+E);
    there are two table one is login and other is student..

    Here is html code :::
    <head>
    </head>
    <body>
              <div id="header">
                   <div id="logo">
                        <h1><span class="ds27"> Student Managment</span></h1>
                   <div id="menu">
              <ul>
                             <p>
                                  <li >Home</li>
                                  <li>Fourm</li>
                                  <li class="active">Register student</li>
                                  <li>Campus info</li>
                                  <li>Log out</li>
                             </p>
                        </ul>
         </div>
                   <!-- start header --></div>
              <!-- end header --><!-- start page -->
    <div id="page">
         <!-- start content -->
         <div id="content">
              <div class="post">
                   <h1 class="title">Welcome To New Arts Commerce & Science</h1>
                             <p class="descr"><small>Posted on January 24th, 2009 by Swapnil adsure</small></p>
                             <p class="descr">
    <table border="1" width="400">
    <form name="form1" method="POST" >
    <SCRIPT language="JavaScript" TYPE="text/javascript">
    function validate()
    {var r = document.form1;
    var email_pat= /\w+@\w+\.\w{1,3}/;
    var name_pat = new RegExp("[^a-zA-Z]");
    if( r.UserName.value=="")
    alert("UserName cannot be blank");
    return;
    if( r.Password.value.length<=6)
    alert("Password Strength too low!! ");
    return ;
    if( document.form1.Password.value!= document.form1.Password2.value)
    alert("The two passwords do not match");
    return ;
    if(r.prn.value=="")
    alert("PRN number cannot be blank");
    if((r.FirstName.value=="") || (r.FirstName.value.length < 3) || (name_pat.test(r.FirstName.value)))
         alert("First Name Could not be Blank and must contain only ALPHABATES");
         return;
    if((r.lastName.value=="") || (name_pat.test(r.lastName.value)) || (r.lastName.value.length < 3) )
         alert("Last Name Could not be Blank and must contain only ALPHABATES");
         return;
    if( r.Address1.value=="")
    alert("Address cannot be blank");
    return ;
    if( r.City.value=="")
    alert("City cannot be blank");
    return ;
    if( r.Phone.value=="")
    alert("Phone Number cannot be blank");
    return ;
    if( r.Email.value=="")
    alert("Email ID cannot be blank");
    return ;
    if(r.CName.value=="")
    {alert("Class Name cannot be blank");
       return ;
    if(r.Year.value=="")
    {alert("Year cannot be blank");
       return ;
    document.form1.method ="post";
         document.validate.action="http://localhost:8080//servlet/sign.class";
         document.form1.submit();
    </SCRIPT>     
                             <tr>
                             <td>User Name
                   <input type="text" align="middle" size="13" name="UserName"></td>
                             </tr>
                             <tr>
                             <td>Password
                             <input type="password" align="middle" size="13" name="Password"></td>
                             </tr>
    <tr>
                             <td>Confirm Password
                             <input type="password" align="middle" size="13" name="Password2"></td>
                             </tr>
                             <tr>
                             <td >PRN
                             <input type="text" align="middle" size="13" name="prn"></td>
                             </tr>
                             <tr>
                             <td>First Name
                             <input type="text" align="middle" size="13" name="FirstName"></td>
                             </tr>
                             <tr>
                             <td>Middel name
                             <input type="text" align="middle" size="13" name="MiddleName"></td>
                             </tr>
                             <tr>
                             <td>Sur Name
                             <input type="text" align="middle" size="13" name="LastName"></td>
                             </tr>
                             <tr>
                             <td>Address
                             <input type="text" align="middle" size="13" name="Address1"></td>
                             </tr>
                             <tr>
                             <td>City
                             <input type="text" align="middle" size="13" name="City"></td>
                             </tr>
                             <tr>
                             <td>Phone Number
                             <input type="text" align="middle" size="13"></td>
                             </tr>
                             <tr>
                             <td>Email id
                             <input type="text" align="middle" size="13" name="Email"></td>
                             </tr>
                             <tr>
                             <td>Class name
                             <input type="text" align="middle" size="13" name="CName"></td>
                             </tr>
                             <tr>
                             <td>year of Appering
                             <input type="text" align="middle"" size="13" name="Year"></td>
                             </tr>
                             <tr>
                             <td>
                   <input type="submit" value="Submit" name="B1" onclick="validate()">
                             <input type="reset" name="c" value="Cancel">
                             </td>
                             </tr> </form></table>
                             </p>
                   </div>
    </body>
    </html>
    In this page IT does not call This lines:
    document.form1.method ="post"
         document.validate.action="http://localhost:8080//servlet/sign.class";
         document.form1.submit()

  • Way to Debug EJB Insert (Database) Errors?

    Howdy y'all,
    Would anyone happen to know of any trick to get the details of a transaction.commit() failure to print in the logs?
    Specifically my problem is, Oracle reports there is a column which fails because the data being stuffed into it is too large - although the data checks out - I checked the lengths of the fields and the widths of the columns and printed the data to the logs so I can manually sift through and ensure none of it exceeds any maximums. It does not seem that any of the data is in violation of any size limits.
    It would be excellent if there was a way to determine which column exactly failed - but I'm going to venture a guess that one is limited by what the host DB provides?
    Many Thanks,
    Alexandra

    For some reason, the freeware database tools we use sometimes show column sizes incorrectly. Where I thought I had a varchar2(4000), I really only had varchar2(1024) - which was only made apparent to me when I went to our DBA out of sheer frustration, and he viewed the schema with his nice Oracle schema browser tool, which showed the correct column allocations.
    So, of course the value of WC 1145 would be too wide for the column! (Having a way to determine the offending column at run time would have really reduced the debug time)
    --Alexandra                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Database Adapter: Insert, relationships, sequences and problems of course

    Hello Everyone!!
    I'm trying to do an insert in an Oracle Express Database with a database adapter. I'm trying to do the insert in two tables: SOLICITUDES with a column called NUMSOLICITUD that is also the primary key of the table and it's populated from its own sequence and the other table whose name is DOCJUST with a field NUMSOL. SOLICITUDES has a 1:M relationship with DOCJUST and the fields used in this relationship are NUMSOLICITUD and NUMSOL. The problem is that when the adapter do the insert, the first insert made on SOLICITUDES is correct, but when it tries to insert in the DOCJUST table, when it's supposed to insert in NUMSOL the same value inserted in NUMSOLICITUDES instead of that, a NULL value is inserted in NUMSOL so the process fails. Is it because the NUMSOLICITUDES column is populated from a sequence? How can I resolve that?
    Thanks!!

    Hi,
    OK, I found the following article: http://soa-bpel-esb.blogspot.com/2010/04/understanding-catch-and-catchall.html
    Using the info from that article I have created a test flow, which contains the same insert database adapter as the production flow. I have placed the Invoke within its own scope and attached a "CatchAll" block to this scope. To this block I have added a "empty" step (do nothing).
    In my tests, I see the desired results i.e. the second time I initiate the flow with the same data, the CatchAll block executes, which does nothing, and processing continues after the scope.
    So far so good - my query is how would I catch the specific error of unique index violation rather than general catchall?
    As before, and assistance/comments greatly appreciated.
    Anit

  • Uploading excel data to database table

    Dear Experts,
                         I have an Excel file which was downloaded from SQL database, now I need to export this data into my 'ztable', for this first I created an internal table of ztable structure and tried to upload into this table through ''TEXT_CONVERT_XLS_TO_SAP".
    But I was unable to get data into the internal table(incompatible type), so now I created an internal table of character type fileds now I able to get data to this internal table, but to put this internal table data to actual database table it gives error, here the actual problem is the fields of internal table are getting concated with blank spaces(observed through debug), I unable to condense these blanks also, (I have created an Excel of my own and put data into it and uploaded that data there is no problem working fine but this problem occurs only for the excel downloaded from SQL db)
                       The problem occurs for quantity and currency fields(I tried through standard FMs also to convert data types ), Could plz suggest something..........
                                                                                    Thank you
                                                                                    Regards
                                                                                    Srinivas

    Hi,
    To upload excel sheet into database table, define a types which is of same as table fields.
    and try it with the function module  TEXT_CONVERT_XLS_TO_SAP
    Here is a sample code:
    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
            EXPORTING
             I_FIELD_SEPERATOR          ='X'   
              i_tab_raw_data             = fs_truxs( TYPE of  truxs_t_text_data.)
              i_filename                 = '<FILE-PATH>'
          tables
              i_tab_converted_data       = <Internal Table>
           EXCEPTIONS
             CONVERSION_FAILED          = 1
             OTHERS                     = 2
          IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
    LOOP AT <internal-table> INTO field string.
    INSERT <DATABASE- TABLE> FROM <field string>.
    ENDLOOP.
    Hope this solves the issue.
    Regards,
    Rajani

  • Column name as a variable in a database trigger

    I am trying to code a pre-insert database trigger to format all varchar2 columns entered into the triggering table. I am using a cursor to get all the relevant column names from all_tab_columns, but do not know how to refer to these values in combination with the ":new" construct within my code. The example below is a very simplified version of what I am trying to do ( it obviously will not work as it is):
    declare
    cursor column_cur is
    select column_name cn
    from all_tab_columns
    where table_name = 'TEMP_ASSESSMENT'
    and data_type = 'VARCHAR2';
    v_columnname varchar2(30);
    begin
    for column_rec in column_cur loop
    v_columnname := column_rec.cn;
    :new.v_columnname := upper(:new.v_columnname); declare
    cursor column_cur is
    select column_name cn
    from all_tab_columns
    where table_name = 'TABLE_X'
    and data_type = 'VARCHAR2';
    v_columnname varchar2(30);
    begin
    for column_rec in column_cur loop
    v_columnname := column_rec.cn;
    :new.v_columnname := upper(:new.v_columnname);
    end loop;
    end;

    Seems to me like the problem in this thread:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:59412348055
    C.

  • Regarding Database MODIFY

    Hi,
    I am updating(or Insert)  database table in a user - Exit, using MODIFY statement.
    On a particualr date, they have created 100 documents. But, in that 96 documents are inserted into the Custom data base table. But, 4 documents are not inserted.
    So, can you please tell me. what are the chances of a "MODIFY" statment can fail.
    If the 2 users are inserting simultaneuously, is there any chance of fail in MODIFY?
    I am not using any locks in my code.
    I am not using an Commit work here as this is user exit.
    Please help me.
    Code :
    MODIFY DBTAB from WA.

    Hi Sandeep,
    No Need for locks,
    As MODIFY statement automatically sets a database lock until the next database commit or database rollback.
    The Possible cause for not updating the records could be.
    At least one line could not be processed as there is already a line with the same unique name secondary index in the database table. 
    means duplicay of records,
    For ex 96 records are inserted so these 96 records contains unique entries in there primary key fields, rest 4 records doesn't contain unique entries in primary key fields.
    for ex in table MSEG- document number is a key field, so you can not put same material number twice,
    Kindly check your data which you are updating in your table, As key fields should have unique entries. This will definately solve your problem.
    Thanks
    Saurabh siwach

  • Insert into table irrespective of sorting order of a field

    Hi All,
    I am not able to insert data in the data base table(YY...) as it is in the internal table.
    I do have data in following order in the internal table :
    I am simply using statement insert (database table) from (wa) in the loop...endloop.
    001   0002  2008  0000494219 001   0000494219          254.02  W4136      Keller & Kalmbach Widex
    001   0002  2008  0000198630 001   0000494219          100.10  W4136      Keller & Kalmbach Widex
    001   0002  2008  0000198418 001   0000494219           39.57  W4136       Keller & Kalmbach Widex
    001   0002  2008  0000198419 001   0000494219           89.93  W4136       Keller & Kalmbach Widex
    but when data is inserted in the table it appears as below:
    Means system is sorting the data in ascending order based on 4th column which is document number.
    001   0002  2008  0000198418 001   0000494219           39.57  W4136       Keller & Kalmbach Widex
    001   0002  2008  0000198419 001   0000494219           89.93  W4136       Keller & Kalmbach Widex 001   0002  2008  0000198630 001   0000494219          100.10  W4136      Keller & Kalmbach Widex 001   0002  2008  0000494219 001   0000494219          254.02  W4136      Keller & Kalmbach Widex
    How can I keep the sequence of data as it is in the internal table when I insert them into data base table.
    Thanks,
    Mark

    Assign one more field (let's say SEQ_NO). In your loop keep on incrementing this field and insert in database.
    You have to add this field as first primary key in your database table also.
    Hence you data will look like
    1 001 0002 2008 0000494219 001 0000494219 254.02 W4136 Keller & Kalmbach Widex
    2 001 0002 2008 0000198630 001 0000494219 100.10 W4136 Keller & Kalmbach Widex
    3 001 0002 2008 0000198418 001 0000494219 39.57 W4136 Keller & Kalmbach Widex
    4 001 0002 2008 0000198419 001 0000494219 89.93 W4136 Keller & Kalmbach Widex
    Regards,
    Mohaiyuddin

Maybe you are looking for