Closing the Connection object

I was looking at one of the database examples in a Java book I recently purchased. In their example they establish the connection in the class with the main. ( is this referred to as the Moment Interval? ) Anyway, they pass the private Connection connection object to another class called AddRecord which implements an ActionListener. In this class, the AddRecord Constructor changes the name to con which is also declared as private in this class. What they don't show is how to close the connection object now that it has a new name. How do I close the connection object.
The example is using an Access mdb and when the appication is closed, the Access.ldb file is still there.
Is there a better solution?
Thanks everyone,
Leo D.

I'm sorry. I meant to say "Where" do I close the connection? If I close the connection in the AddRecord Class, then I won't be able to add another record. And I can't close the connection in the moment interval because I've declared the connection object in class AddRecord as Private. Should I give the connection object package access?
Thanks,
Leo D.

Similar Messages

  • Difference between closing the connection before and after committing user transaction?

              I was wondering what's the difference between closing the connection before committing
              the transaction versus closing the connection after committing the transaction?...
              for e.g....
              Scenario 1.........
              UserTransaction useretran;
              usertran.begin();
              Connection con = datasource.getCOnnection();
              // do bunch of stuff...
              conn.close();
              usertran.commit()
              Scenario 2...
              UserTransaction useretran;
              usertran.begin();
              Connection con = datasource.getCOnnection();
              // do bunch of stuff...
              usertran.commit()
              conn.close();
              thanks....
              Srini
              

    Hi. As long as you're sure there's a transaction going on, and the connection
    is a transaction-aware object (from a TxDataSource), either will be fine.
    In the first scenario the actual semantics of the close() call are less than
    normal, because we really don't close the connection or return it to the
    pool until the actual transaction commits, and in the second case, we have
    already taken the connection out of your service as of the commit().
    The second scenario is the usual coding style. If there's ever a chance your
    code will get non-transaction-aware connections, it is crucial to close
    connections, and I always recommend putting the close() in a finally block
    so it's guaranteed to happen.
    Joe
    srinivas wrote:
    I was wondering what's the difference between closing the connection before committing
    the transaction versus closing the connection after committing the transaction?...
    for e.g....
    Scenario 1......... UserTransaction useretran; usertran.begin(); Connection con =
    datasource.getCOnnection(); // do bunch of stuff... conn.close(); usertran.commit()
    Scenario 2... UserTransaction useretran; usertran.begin(); Connection con = datasource.getCOnnection();
    // do bunch of stuff... usertran.commit() conn.close();
    thanks....
    Srini

  • Significnce of making the Connection object explicitly as null

    Iam using java.sql.Connection object to make connection to DB400 database and in the finally block closing the connection as con.close();
    90% of the time query is executing fine and getting correct results. But some times the updated values in the data base are not getting reflected in the result set. ie: ResultSet object is not refreshing properly(not always but sometimes). After making the code in the finally block as follows I feel it is working fine
    if(con != null)
    con.close();
    con=null;
    Can some one explain the significance of making an object explicitly to null.

    I am facing the same issue again. The resultSet and the stament are getting closed properly but the query is not fetching the updated results. If i execute the same query using a client(WinSQL), then the updated values are reflected. Also if i change any of the where conditions in the query(adding one more 'and' condition or 'or' condition ), then the query is giving correct results. Is there any resultSet caching occurs in websphere

  • Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

    Hi,
    I am using APEX version 4.2.1.00.08 with Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    I've developed an application, that was working fine till 3 days ago...
    At the moment, I can log into the application but when I enter my ID/PW it takes me to my 1st page but then it runs for a mint or so (trying to load charts) and then generates following error message
    No data received
    Unable to load the webpage because the server sent no data.
    Here are some suggestions:
    Reload this webpage later.
    Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
    interestingly, I haven't changed anything within the application
    I've tried it with Chrome Version 27.0.1453.116 m and IE 8.0...
    with IE 8.0, it shows I/O Error in place of my graphs and get's a pop up message that displays "Error - error unknown"
    The only thing that I can recall doing differently is logging via remote desktop connection, but I've used remote desktop in the past as well and it worked.
    Please advice

    anyone...?

  • Gateway unexpectedly closed the connection..

    When I try to Test Connection for the Active Directory Resources it shows the following error
    The gateway unexpectedly closed the connection with an exception, check the gateway trace for more information. ==> java.net.SocketException: Connection reset by peer: socket write error
    Previously it has working fine for me...

    Kannan SB wrote:
    I Have resolved my issue... I had remove the Gateway service and reinstall the service & restart the machine and try it got success...Still I have face the same issue, only it works for sometime I means while we restart the service it will work after some mins it got failed to perform the service.. Please suggest me for that....
    I have migrated Sun Identity Manager 8.1 Patch 7 to Oracle Waveset 8.1.1 Still the issue persists ...

  • An error occured while opening the connection: Object reference not set to

    After I uninstalled Oracle Developer Tools for Visual Studio .NET 10.1.0.4 and installed Oracle Developer Tools for Visual Studio .NET with Oracle10g Release 2 ODAC 10.2.0.2.21 I got the error message below when I want to connect to my 10g database using Oracle Explorer.
    Error:
    An error occured while opening the connection: Object reference not set to an instance of an object
    I use OracleConnection to open also cannot be done. But I use Oracle SQL Developer I can connect to orcl that I cannot connect using ODAC 10.2.0.2.21 in my laptop.
    Please help me.
    Ming Man

    Sorry my mistake, I double checked, the one I uninstalled is ODAC 10.2.0.2.20 and not ODAC 10.1.0.4.
    But I have that error.
    Ming Man

  • The VI closed the connection : error 1074360302 at property node(arg 1)

    hi!
    I'm trying to running a code which apply the control of my myRIO through a VI on my host computer. A video stream of data is also going to be send from myRIO to the Host Computer VI. However, I am getting the "Host Computer VI" closed the connection. I have no idea why.
    And at the Host Computer keep giving out error 1074360302 occured at Property Node (arg 1) in myRIO vi.
    I would be glad if someone could help me.
    Thank you.
    Attachments:
    Picture1.png ‏81 KB

    Hi e_pah,
    Thanks for your response, what sort of camera are you using? This error has been previously seen with a Stingray camera when the IMAQ drivers aren't quite up to date.
    So firstly, we need to make sure the IMAQ drivers are updated.
    Further questions regarding your application:
    Did this VI ever run?
    Does this error occur everytime the VI is run?
    What is the the property node doing?
    Many thanks
    Ingram

  • Getting the connection object in graph

    As part of Denormalizer component's Denormalize property where we have the logic of collapsing/denormalising the records we want to execute a sql query using PreparedStatement which requires Connection object.how do I get the connection object and execute a query.Can some one please share the java doc of the classes I can use.
    Do I get any class under org.jetel package which can be useful to get the Connection object.

    As part of Denormalizer component's Denormalize property where we have the logic of collapsing/denormalising the records we want to execute a sql query using PreparedStatement which requires Connection object.how do I get the connection object and execute a query.Can some one please share the java doc of the classes I can use.
    Do I get any class under org.jetel package which can be useful to get the Connection object.

  • Where to store the Connection object?

    Hi,
    I am using JDBC together with JSF technology to building web applications. I have the following questions:
    1. Where do we usually store the open Connection object so that every class in my web application can make use of it to update or retrieve database data?
    2. Since JSF uses managed-beans which is not a servlet itself, if I store the Connection object as an attribute in the application scope then it can only be retrieved from a servlet.
    3. If I make the Connection object on every class where I would like to have database access, it seems that it is not following good practice since this would create duplicate codes in every Java class which is going to have database access.
    Does anybody have an idea? Thank you.

    Hensome wrote:
    1. But how do I use the managed bean within a servlet? Could you write some simple sample codes?
    2. If I only use simple navigation rules and backing beans, when the submit button is clicked then the action method of the managed bean is triggered. I will then trigger the action which uses JDBC for database access. This whole process does not go through a particular servlet. Is this also possible? If yes, how?
    Thank you.the process does run through a particular servlet, it's the faces servlet and is defined by something that looks like
      <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
      </servlet> in your web.xml file. You don't have direct access to it, but you can save references to objects in the session or request so other objects can access it. Lets say that your faces code uses a DAO to read some data and you want to pass the data to a servlet, what you need to do something like:
         List data = myDAO.read();
         FacesContext facesContext = FacesContext.getCurrentInstance();
         HttpSession session = (HttpSession)facesContext.getExternalContext().getSession(true);
         session.setAttribute("myData", data);this will save the data object or list in the session as an attribute. Then, when the other servlet runs, you can do something like:
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
         HttpSession session = request.getSession(false);
         Object obj  = session.getAttribute("myData");
         List myData = (List)obj;
    }          Now the servlet has access to the list of data read by the faces bean. You shouldn't directly access faces beans themselves from another servlet, you should instead access POJOs that you have defined or collections of them.

  • Univers Designer : JZ0C1, IOException closed the connection

    Hi !
    We get a very strange error when we work in Univers Designer (we're in BO 4.1) when we're working with Derived Table.
    For some reason when we edit a Derived table in a universe (connected to a Sybase database), we received an error message "JZ0C1" saying that we get an IOException and it's closed the connection.
    We get the error message when we click on "Check Syntax" Button in the edit window of the derived table.

    This can mean that the target end has already closed without reading all the data you are trying to send.

  • The remote device closed the connection!!! HELP

    Hi,
    Brought the Ms-6967 Bluetooth USB adapter so I could connect it to my nokia 7650. But have had big problems which failed in me getting anything out of the product.
    For starters every time I reboot my pc, I have to re-install the driver for the Bluetooth dongle? because my operating system (XP) finds this hardware every time I reboot and doesn't seem to remember the last time I install it.
    Plus when I use the software it actually communicates with my Nokia 7650 as in sending a message asking for permission to link pc to phone and when I answer yes on my nokia it replies with " The Bluetooth serial port connection failed: The remote device closed the connection?
    I've wasted so many hours now on this and had no luck. So if anyone has the smallest piece of help to give I would be well happy,
    Cheers,
    DRGonzo247

    Having seen similar symptoms recently you might want to check that you haven't had a browser hijacker installed - check your proxy settings to see if the browser is trying to use a proxy server, or, if you usually use a proxy, check to make sure it hasn't
    been changed. (In IE go to Tools->Internet Options->Connections->Lan Settings.)
    Good luck!

  • Populate County for Supplier Address of the Connection Object

    Hi
    Is there any way that we can populate county (Region) field for supplier address of the connection object i.e premise address (ISU) in SAP system? This is not a mandatory field hence is not filled up by customers (Business Partners).
    County here I mean is eg:
    Country is UK:
    County is Essex then Region code is "ES" etc..
    Please provide your valuable suggestions
    Note: There are billions of customers for which region needs to be populated.
    Thanks and Regards
    Ishi

    Any idea?
    I want to maintain County/Region for UK in Supplier SAP system of ISU..
    Thanks

  • Having the connection object for the specific schema

    hi
    My application interacting with the database of having many no of schema's. I need to create a connection object which is pointing to the specific schema in my database. This is help me to avoid writing schema name in the query every time.
    Thanks
    Siva

    How to specify the schema name in properties file?
    Say for example, i created properties file like that,
    Properties props = new Properties();
    props.setProperty("user", "username");
    props.setProperty("password", "password');
    In which property i can set for schema?

  • RDP to VDI 3 fails with 'Administrative Task closed the connection'

    The RDP to the VDI 3 login page described in the page below would be a really useful feature for us. Unfortunately when I connect using MSTSC (Windows XP SP 3) the screen goes black, then a message pops up with 'The connection was closed by an administrative task' (or words to that effect).
    Any idea on how to resolve this issue?
    http://wikis.sun.com/display/VDI3/Accessing+Desktops+with+Microsoft+RDC
    Thank you in advance for any replies,
    Dono

    Finally worked this one out.
    Turns out I had two pools assigned but it still eludes me how to set one to the default...
    Anyway, what was required was to clear the 'Prompt for credentials' and use the <username>::pool= etc etc to connect to the pool.
    Doesn't render as quickly as using the Sun Ray DTU but it's good enough.
    Many thanks,
    Donovan

  • Probem in creation of the connection object

    Hi All,
    We have deployed a e-billing application, with Weblogic 8.1 (SP 2) being used as the Application Server.
    When we try to login with a valid userid existing in the database, initially it works fine for 2-3 attempts, but after this when we try again, it fails to login and in the background we are getting the error:
    weblogic.transaction.internal.ResourceAccessException: Transaction has timed out when making request to XAResource 'weblogic.jdbc.wrapper.JTSXAResourceImpl'.
         at weblogic.transaction.internal.XAResourceDescriptor.startResourceUse(XAResourceDescriptor.java:610)
         at weblogic.transaction.internal.XAServerResourceInfo.start(XAServerResourceInfo.java:1074)
         at weblogic.transaction.internal.XAServerResourceInfo.xaStart(XAServerResourceInfo.java:1007)
         at weblogic.transaction.internal.XAServerResourceInfo.enlist(XAServerResourceInfo.java:203)
         at weblogic.transaction.internal.ServerTransactionImpl.enlistResource(ServerTransactionImpl.java:419)
         at weblogic.jdbc.jts.Driver.createLocalConnection(Driver.java:207)
         at weblogic.jdbc.jts.Driver.connect(Driver.java:154)
         at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:305)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at weblogic.ejb20.manager.BeanManagedPersistenceManager.scalarFinder(BeanManagedPersistenceManager.java:81)
         at weblogic.ejb20.manager.BaseEntityManager.scalarFinder(BaseEntityManager.java:1580)
         at weblogic.ejb20.manager.BaseEntityManager.remoteScalarFinder(BaseEntityManager.java:1514)
         at weblogic.ejb20.internal.EntityEJBHome.finder(EntityEJBHome.java:553)
         at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:166)
         at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284)
         at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:400)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    This was the initial error that we used to get but then the error message was different (I am not sure about the reason for the change in error message)
    <Exception>java.rmi.RemoteException: javax.ejb.EJBException: Error looking up connection: java.sql.SQLException: No JDBC connection can be made
    because the transaction state is
    Marked Rolledback</Exception>
    The problem (so far I could get it) is happening when the connecion class is being instantiated by the datasource API:
    DataSource ds = null;
    Connection conn = ds.getConnection();
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    return conn;
    Any suggestions to the following problem will be of great assistance.
    Thanks & Regards
    Neeraj Kanodia

    Hi,
    I think that this XAER_RMERR is not from Oracle driver; instead the weblogic transaction manager itself throws it. The sequence is like this:
    - At some point in the transaction, a new sql is to be executed.
    - The DataSource manager (of weblogic) gets the XAResource of the connection and tries to enlist that with current transaction.
    - At the point, transaction manager detects that the transaction already timed out (JTA timeout) and marked for rollback.
    - The transaction manager throws XAException with error code set to XAER_RMERR, which you see in the stack trace.
    It does not look like a real issue except the fact that the transaction has timed out which of course can happen if the transaction is running for long time. I suspect that sometimes this problem may lead to connection leak also. And I found some known issues on this exception, to confirm that I would like to have a look in to your log file. Kindly provide me the log file, which contains this exception.
    Regards
    Anilkumar kari

Maybe you are looking for