Synchronizing DB updating in servlet

hi,
i'd like to the know what code I should synchronize when updating my database. I currently just have the lock as follows in a servlet:
synchronized(this){
            statement.executeUpdate();
       }but i'm wondering if this is enough and if i should synchronize my
statement.setString(x, x) calls?
thanks

Only one object at a time may access the synchronized block, so that will work fine.

Similar Messages

  • Make synchronous the update process of the FB01 transaction.

    Hello, we are using the BTE 1080 that is inside of the FB01 transaction
    to execute a "call transaction" to the F-51. At this point we use the
    FI accounting document data (identified by: {BUKRS, BELNR, GJAHR})
    "created" by FB01 as an input to the F-51 "call transaction".
    Due to the update process in the FB01 is asynchronous (in update task)
    some times the update process delays longer than usual and the F-51 fails
    because is unable to find the FI accounting document data in the database.
    We could use the "wait" instruction to wait for a period of time until the
    "update task" write data to the database, but we don't know how much
    time it will take. We would like to know if it is possible to make synchronous
    the update process of the FB01 in order to warranty the existency of the
    data in the database that will be used by the next transaction F-51.
    Thank you and best regards,
    José.
    Edited by: Ivan Gonzalez on Sep 15, 2010 2:48 AM

    Hi,
    I don't think it's possible. You can do a simple select from BKPF and if the new document is already there then don't wait. Otherwise wait for reasonable time and check again.
    Cheers

  • Diff between synchronous & asynchronous updates of database with call trans

    Hi Everyone,
               I want to know the difference how synchronous and asynchronous
    database update in call transaction method.
    thanks

    Hi,
    In batch session interface: - Asynchronous processing means Transfers data for multiple transactions - Synchronous database update means during processing, no transaction is started until the previous transaction has been written to the database.
    In CALL TRANSACTION: - Synchronous processing means Transfers data for a single transaction. Synchronous and asynchronous database updating both possible The program specifies which kind of updating is desired. Separate LUW for the transaction The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.
    Difference between Synchronous and Asynchronous processing?
    Re: synchronous........
    Suggest you to Search in <b>SDN with key - Synchronous or asynchronous .</b>
    Will get few more useful related Posts.
    Reward points if this Helps.
    Manish

  • Synchronous asynchronous update

    what is difference between synch and asynch update???
    how it affects database update???

    hi,
    For Update you have
    A - asynchronus - does not wait for next update in the queue
    S - Synchronus - waits until the previous update is completed before a new request is considered
    L - Local update - Uses a different work process to trigger call function in update task.
    In synchronus method until one record process takes place into database next record will not be processed.
    In asynchronus immedate updation of data into database table.
    Check this link for more detailed information:
    http://fuller.mit.edu/tech/sync_asynchronous.html
    'A', 'S' and 'L' are the update modes in CALL transaction method.
    I will give you a simple example to explain this.
    Suppose that there are 30 records in total and an error has occured in the 5th record.
    In asynchronous, update is done for every 30 records while in synchronous one,
    update is done only upto the 4th record.
    So only after the record in the fifth one is eliminated, remaining others are processed.
    Have a look at this URL from SAP Help:
    http://help.sap.com/saphelp_46c/helpdata/en/41/7af4cba79e11d1950f0000e82de14a/frameset.htm
    Regards
    Reshma

  • Synchronized (this)  inside a servlet

    guys, is it wrong to use synchronized (this)" in a servlet????? what do you think will happen if this code is inside doPost in a servlet
    synchronized (this) {
             this.wait(retry);
           }

    Definitely do not synchronize on the servlet ... you can certainly restrict the granularity of the sycnronization ... you will be turning your servlet into a single threaded servlet ... yikes.
    Anyway, I have synchronized on the session and for the most part it works. After some time I did run into some locking problems which I presume were because the container running in a different thread needed to acquire the lock on the session to do something ... just guessing.
    Anyway, since then I have relied on a lock object that I place inside the session ... I lock on that object rather than on the session and have found this to work without any problem at all.

  • Synchronized problem in JSP/Servlet, please help me.

    Hi, all
    I have many processes in one JSP page or Servlet program of my project.
    When many people visit at one time, then the project throws some SQL/DB Errors.
    I have updated it and test it many times, I think, that is a synchronized problem.
    At last I used ��synchronized (this){my JSP/Servlt SQL/DB processes}�� to synchronize
    The process. Then the errors removed.
    And now I think that too danger to use the ��synchronized (this){}�� to synchronized.
    If use it then some other problem may be growling on. Such as when one people need to use
    This service others must to wait, the process may be too slow! And when an exception throws
    from the SQL/DB or some other place, what I do? Need any advice from you.
    Sincerely
    Urey
    *** my JSP/Servlt Server is tomcat ***

    As Chuck points out, there isn't a new instance of the Servlet/JSP for each request - they are probably all calling the same instance so any state will be shared. If your Connection is stored as a member variable then you'll have problems with it already being in use if two people hit the page at the same time.
    Limited resources such as database connections should ideally be pooled anyway to ensure that you're not opening them all the time and that you can control how many are open across the entire application. Then you'd simply need to get a fresh connection out of the pool at the top of the page and make sure you put it back when you're done.
    Incidentally, although it might work, synchronizing the database access in the JSP would be a bad idea since you'd just create a queue of requests waiting to use the one Connection whereas you really need a number of Connections to deal with everyone simultaneously.
    If you need some example code for a simple JSP using a database connection pool (DataSource) just say.
    Hope this helps.

  • Updating through servlet fails!

    Hello everyone!
    I have a servlet which updates the emps table in oracle database.
    --the code
    package oz;
    import java.sql.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    public class UpdateScottEmployees extends HttpServlet{
    public void doGet(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException{
    doPost(request,response);
    }//doPGet
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException{
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    Connection cn = null;
    Statement stm = null;
    try{
    //Load the driver
    Driver drv = (Driver) Class.forName("JData2_0.sql.$Driver").newInstance();
    //Oracle Connection
    cn = DriverManager.getConnection("jdbc:JDataConnect://zaf/scott_emp:scott:tiger");
    stm = cn.createStatement();
    String upd = "INSERT INTO emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)" +
    "VALUES(" +
    request.getParameter("theempno") + "," +
    "\"" + request.getParameter("theename") + "\"," +
    "\"" + request.getParameter("thejob") + "\"," +
    request.getParameter("themgr") + "," +
    "\"" + request.getParameter("thedate") + "\"," +
    request.getParameter("thesal") + "," +
    request.getParameter("thecomm") + "," +
    request.getParameter("thedeptno") + ")";
    stm.executeUpdate(upd);
    cn.close();
    stm.close();
    out.println("<P>Update done!</P>");
    }catch(Exception e){
    out.println(e.toString());
    }//doPost
    }// UpdateScottEmployees
    and the html file
    <HTML><HEAD>
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    <H3 align="center">Update form</H3>
    <BR>
    <FORM ACTION="../../servlet/oz.UpdateScottEmployees" METHOD="POST">
    Employee number:<INPUT TYPE="text" NAME="theempno"><BR>
    Employee name:<INPUT TYPE="text" NAME="thename"><BR>
    Employee job:<INPUT TYPE="text" NAME="thejob"><BR>
    Employee manager:<INPUT TYPE="text" NAME="themgr"><BR>
    Employee hiredate:<INPUT TYPE="text" NAME="thedate"><BR>
    Employee sal:<INPUT TYPE="text" NAME="thesal"><BR>
    Employee commission:<INPUT TYPE="text" NAME="thecomm"><BR>
    Employee Department no:<INPUT TYPE="text" NAME="thedeptno"><BR>
    <INPUT TYPE="SUBMIT" VALUE="update">
    </FORM>
    </BODY>
    </HTML>
    When i click the submit button i get the following message:
    java.lang.ClassNotFoundException: JData2_0.sql.$Driver
    However i have tried the driver class and it seems to work. What's the problem?
    Any help would be appreciated!
    Thanks in advance!

    Hello again!
    I think my classpath is set correctly because a simple java program placed in the same directory succeeds with the connection.Do you think the problem is placing the driver class inside doGet() or doPost() ?

  • Db updation from servlet

    hi ,
    I am new to sevlets and trying to update an access db through a servlet using the
    code given below.
    String strUpdate ="UPDATE TABLE ProposalTrackingSystem "+
                        "SET Responsibilities = '"+strRespo+"'"+
                        "WHERE ProposalNumber = "+strPN ;
    where strRespo and strPN are String variables.
    It gives the following error :
    javawebserver: The Update Query : UPDATE TABLE ProposalTrackingSystem SET Respon
    sibilities = 'Full .. No Less'WHERE ProposalNumber = 1
    javawebserver: Exception thrown :[Microsoft][ODBC Microsoft Access Driver] Synta
    x error in UPDATE statement.
    pleeeeezzz help...
    thanks in advance

    well, thanxxxx sudha.. but before i got ur reply i used this :
    String strUpdate ="UPDATE ProposalTrackingSystem SET Responsibilities='"+strRespo+"' WHERE ProposalNumber="+strPN;
    and it runs now
    the blankspace wala funda .. am aware of.. was just a typing error..
    thanx again for ur prompt reply
    kuttudi

  • Updating a servlet

    Here is a scenario:
    A user enters a query and submits it to servlet. The servlet prints "thanks for the visit, ur query is being dealt with". At the same time the servlet is accessing a database and searching for user's query. Then the servlet updates itself with the information from the database.
    My real question is that how can a servlet update itself. For example, how would it know that it has retrieved data from the database.
    Would I need to use respond.setHeader(....) method.
    Thanks
    Qasim

    in your code to get information from database you would have something like
    while( resultset.next()) {
    //keep reading
    once all the information is taken from database and you are out of while loop,at that point you can direct the out put to your page exactly the way u sent thank and it will reflect the info from db in the same page where u had "thank u " for user.
    I hope this answers ur question
    Khalid Ali

  • Why I need to restart my my server to update my servlet in WL5.1

              Hai
              We have servlets and ejbs in our acchitecture and using weblogic5.1. For EJBs
              weblogic have given hot deploy. But for every change of servlets currently we
              are stopping the server and replacing the servlet class and starting the server.
              Since we getting drastic changes we need to update or deploy servlet in the existing
              running server. Is there any thing is available for servlets or normal classes
              to update in the server. Thanks In Advance
              Kiran N
              

              Hi,
              What is the service pack you are using?
              You should be able to dynamically load the servlet classes.
              Please make sure that you put your servlet classes in servlet classpath:
              weblogic.httpd.servlet.classpath=....
              For every reload check secs server will check for any changes in the classes
              and loads if they are changed.
              Also make sure that you do not have the same class in the system classpath.
              --Vijay
              "Kir" <[email protected]> wrote:
              >
              >Hai
              >
              >We have servlets and ejbs in our acchitecture and using weblogic5.1.
              >For EJBs
              >weblogic have given hot deploy. But for every change of servlets currently
              >we
              >are stopping the server and replacing the servlet class and starting
              >the server.
              >Since we getting drastic changes we need to update or deploy servlet
              >in the existing
              >running server. Is there any thing is available for servlets or normal
              >classes
              >to update in the server. Thanks In Advance
              >
              >
              >Kiran N
              

  • Update a servlet automatically

    Hello,
    I try to make a servlet.
    but each time i change my .java file, i need to stop and start again TOMCAT for viewing the change on my servlet.
    Does he have a way for each time i change my .java file TOMCAT take the update automatically?
    i use TOMCAT 5 with Apache on a Gentoo linux.
    thanks for helping me!

    If you have defined your context definition outside server.xml (should be in path as below),
    <TOMCAT_INSTALL/conf/<enginename>/<hostname>/<your_context_name.xml>An example application called webtest running on localhost and with the default engine name as Catalina would have this path.....
    <TOMCAT_INSTALL/conf/catalina/localhost/webtest.xmlall you have to do is add an attribute reloadable = "true" to your context definition in the xml above.
    <?xml version='1.0' encoding='utf-8'?>
    <Context docBase="D:/ram/technical/webtest" path="/webtest"
    reloadable="true" workDir="D:\ram\technical\webtest\work">
    <!-- define context resources here -->
    </Context>Cheers,
    ram.

  • How to synchronized TreeView update?

    Hello forum,
    I'm try to update treeviw @ runtime but i recevid this errorr:
    java.util.ConcurrentModificationException
         at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
         at java.util.ArrayList$Itr.next(ArrayList.java:791)
         at com.sun.javafx.collections.ObservableListWrapper$ObservableListIterator.next(Unknown Source)
         at javafx.scene.control.TreeView.getItem(Unknown Source)
         at javafx.scene.control.TreeView.getTreeItem(Unknown Source)
         at javafx.scene.control.TreeCell.updateItem(Unknown Source)
         at javafx.scene.control.TreeCell.access$000(Unknown Source)
         at javafx.scene.control.TreeCell$1.invalidated(Unknown Source)
         at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(Unknown Source)
         at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown Source)
         at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(Unknown Source)
         at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(Unknown Source)
         at javafx.beans.property.IntegerPropertyBase.markInvalid(Unknown Source)
         at javafx.beans.property.IntegerPropertyBase.set(Unknown Source)
         at javafx.scene.control.IndexedCell.updateIndex(Unknown Source)
         at com.sun.javafx.scene.control.skin.VirtualFlow.setCellIndex(Unknown Source)
         at com.sun.javafx.scene.control.skin.VirtualFlow.addTrailingCells(Unknown Source)
         at com.sun.javafx.scene.control.skin.VirtualFlow.layoutChildren(Unknown Source)
         at javafx.scene.Parent.layout(Unknown Source)
         at javafx.scene.Parent.layout(Unknown Source)
         at javafx.scene.Parent.layout(Unknown Source)
         at javafx.scene.Parent.layout(Unknown Source)
         at javafx.scene.Parent.layout(Unknown Source)
         at javafx.scene.Parent.layout(Unknown Source)
         at javafx.scene.Scene.layoutDirtyRoots(Unknown Source)
         at javafx.scene.Scene.doLayoutPass(Unknown Source)
         at javafx.scene.Scene.access$3000(Unknown Source)
         at javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
         at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
         at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
         at com.sun.javafx.tk.quantum.QuantumToolkit$8.run(Unknown Source)
         at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
         at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
         at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
         at java.lang.Thread.run(Thread.java:722)Is there a way to synchronize update access to observable array list in treeview?
    Thanks in avanced,
    palban

    I have a Listener wich send event to treeview...
    public void createMarkers(final MapViewer map, TreeContent treeContent) {
            StateControllerSigletone.getStateController().addMarkerListener(map);
            StateControllerSigletone.getStateController().addMarkerListener(treeContent);
            Task task = new Task() {
                @Override
                protected Object call() throws Exception {
                    if (db.connetti()) {
                        String query = "SELECT `country` , `city` , `latitude` , `longitude` "
                                + "FROM `csv` "
                                + "WHERE (`country` = \"US\" OR `country` = \"IT\") "
                                + "ORDER BY  `csv`.`region` DESC "
                                + "LIMIT 0 , 10000";
                        ResultSet rs = db.eseguiQuery(query);
                        try {
                            double lat = 0;
                            double lon = 0;
                            int i = 0;
                            while (rs.next()) {
                                lat = rs.getDouble("latitude");
                                lon = rs.getDouble("longitude");
                                MapMarker marker = new MapMarkerDot(map, lat, lon, rs.getString("country") + ": " + rs.getString("city"));
                                StateControllerSigletone.getStateController().mapMarkerAdded(marker);
                                updateProgress(i++, 10000);
                        } catch (SQLException ex) {
                            Logger.getLogger(NEDiscoverer.class.getName()).log(Level.SEVERE, null, ex);
                        db.disconnetti();
                    return true;
            };then, the new Item was addedd...
    @Override
        synchronized public void mapMarkerAdded(MapMarker marker) {
            TreeItemMarker item = new TreeItemMarker(marker);
            rootItem.getChildren().add(item);
        }Edited by: palban on 24-mar-2012 5.57

  • Why is this table trigger not firing when insert/update from servlet?

    Hi!
    I have this servlet that parses XML and stores values into Oracle tables. I have created a table trigger so that when one table is updated, a trigger is fired and the current system date is store in another table's field.
    I have tested the trigger in Toad and it works, that is, if I update the table that the trigger is set to, the SYSDATE is stored as intended.
    Here is the trigger's code:
    DECLARE
    tmpVar NUMBER;
    NAME: transaction_time
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 9/14/2007 1. Created this trigger.
    NOTES:
    Automatically available Auto Replace Keywords:
    Object Name: transaction_time
    Sysdate: 9/14/2007
    Date and Time: 9/14/2007, 8:00:42 AM, and 9/14/2007 8:00:42 AM
    Username: (set in TOAD Options, Proc Templates)
    Table Name: MS_RESLIMITS (set in the "New PL/SQL Object" dialog)
    Trigger Options: (set in the "New PL/SQL Object" dialog)
    BEGIN
    tmpVar := 0;
    UPDATE MS_Misc SET mi_lastrun = SYSDATE;
    EXCEPTION
    WHEN OTHERS THEN
    -- Consider logging the error and then re-raise
    RAISE;
    END transaction_time;
    Now, when the table is updated by the servlet, the trigger does not fire. And here is the code from the servlet:
    --- <start of code> ---
    boolean recordExists =
    this.isRecordPresent("MS_ResLimits", "rl_compcode",
    compCode, url);
    Connection rlConn = null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    rlConn = DriverManager.getConnection(url, dbUser,
    dbPwd);
    Statement stmt = rlConn.createStatement();
    PreparedStatement xmlUpdate = null;
    if (recordExists) {
    xmlUpdate =
    rlConn.prepareStatement("UPDATE MS_ResLimits SET rl_compcode = ?, rl_maxreslimit= ? WHERE rl_compcode =?");
    xmlUpdate.setString(1, compCode);
    xmlUpdate.setString(2, maximumReservationDate);
    xmlUpdate.setString(3, compCode);
    } else {
    xmlUpdate =
    rlConn.prepareStatement("INSERT INTO MS_ResLimits VALUES(?,?)");
    xmlUpdate.setString(1, compCode);
    xmlUpdate.setString(2, maximumReservationDate);
    } //end-if-else
    int n = xmlUpdate.executeUpdate();
    rlConn.commit();
    } catch (Exception ex) {
    out.println(ex.toString() +
    "-> error inserting Max Reservation Date<br>");
    } finally {
    if (rlConn != null) {
    rlConn.close();
    } //end-try-catch-finally
    --- <end of code> ---
    What causes the trigger to fire? the commit? My understanding is that executeUpdates are in autocommit mode by default, or am I mistaken? Do I have to programmatically send something to the DB so that the trigger fires?
    BTW, I'm using JDeveloper 10.1.3.3.0. The project is being compiled with Java 1.5.0_06. The servlet is running in OCJ4 standalone. DB is 10g (don't know the release version).
    ...and, for some reason this message is not keeping format from my edit window to the post...
    Thx!
    Message was edited by:
    delphosbean
    Message was edited by:
    delphosbean
    Message was edited by:
    delphosbean

    You are supposed to be able to preserve you formatting using the <pre></pre> tags but I can't get this to work either<br>
    <br>
    Patrick.

  • Status updates while servlet is running...

    I have a servlet that launches a dozen different thread to process a bunch of network information. Now, these all work fine and I have a please wait page while they run (about 45 sec) but the users are getting ansy during this time and would like some feedback while the process are running.
    I thought, no problem, I'll send a message back to the user when each process thread finishes. No such luck, I get one of two results with my attempt at coding this. First, the messages do not show until the main controlling servlet is finished and they are just thrown in at the top of the results page. Or, second, the messages all come up as they are suppose to but then the results page never displays.
    What am I doing wrong? Thanks!
    Ross

    I set up a <DIV> tags on the request page that has the Please wait HTML in it. Then during the submit, I call some JavaScript that hides the first DIV section and displays the second. Bceause the DOM is not standard across browsers, hence why I want to have the servlet do this rather than my current method. I needed to write this JavaScript function so this would work in most browsers:
    function PostandWait() {
        if(document.getElementById) {
            document.getElementById('main').style.display='none';
            document.getElementById('main').style.visibility='hidden';
            document.getElementById('banner').style.visibility='hidden';
            document.getElementById('wait').style.display='block';
        else if(document.layers) {
            document.layers["main"].visibility="hidden";
            document.layers["wait"].visibility="show";
        else if(document.all) {
            document.all["main"].style.visibility="hidden";
            document.all["wait"].style.visibility="visible";
        else {
        document.jobform.submit();
    }//PostandWait

  • Synchronizing Software Updates Issue

    I have the synchronization schedule set to run everyday, but when my ADR ran at 11:30 PM on Patch Tuesday there were no Patch Tuesday released software updates in the Software Update Group. So then I deleted the Software Update Group that my ADR created
    and then I manually ran the synchronization. After that, I manually ran the ADR and then all of the Patch Tuesday released software updates were there. 
    I checked the wsyncmgr.log on my Standalone Primary Site Server where the SUP role is also installed and it shows that every sync has started at midnight. So now it seems that the initial synchronization did occur prior to the Patch Tuesday released updates. 
    Am I right on this? If so, should I create a custom Synchronization Schedule to occur daily around 10 PM or so?
    Thanks

    Yes I know.
    The sync does run before the ADR runs, but the problem is the sync runs before the Patch Tuesday updates are released from Microsoft. So if Microsoft releases their Patch Tuesday updates at 2 PM, then the sync that runs at midnight, obviously, would not
    grab the metadata from these updates. Therefore, my ADR will not be able to use these updates. 
    I guess what I will do is just keep the Simple Schedule for the sync as it is and I will just change the ADR to run early on Wednesday mornings, like around 2 AM or so. 
    How does that sound?
    How do you SCCM MVPs usually do this?
    Thanks

Maybe you are looking for