Managing connections best practices

Hi,
I have a web application that uses JDBC to retrieve information and display it. My question is: What is the best way to manage your connection objects? I know using a connection pool is probably best, but I'm curious to hear good alternatives? If I need a connection in several places in my web-app, then storing one Connection object in the session seems like a good idea. This way I don't have to create and close my connections each time and slow down performance. But what happens to the connection when the user is no longer in the session. Does the database close the connection implicitly and is there any cons to doing it this way?
Thanks

Hi,
I have a web application that uses JDBC to retrieve
information and display it. My question is: What is
the best way to manage your connection objects? I know
using a connection pool is probably best, but I'm
curious to hear good alternatives? If I need a
connection in several places in my web-app, then
storing one Connection object in the session seems
like a good idea. The term "session" usually refers to a 'space' that exists both on a client and a server.
Connections never exist on more than one machine or even more than one application.
This way I don't have to create and
close my connections each time and slow down
performance. But what happens to the connection when
the user is no longer in the session. Does the
database close the connection implicitly and is there
any cons to doing it this way?
Well one con is that in general you have no control over when the "session" is closed. Thus you must rely on finalize in a java class to close your connections via the GC. And unless you have a really unusual database, or you only use a couple of "sessions" an hour, you are going to run out of connections. This is because GC is optimized for memory handling and not any other resource (a connection is a resource.)

Similar Messages

  • External connectivity best practice

    Hi,
    I would like to know what are the best practices to have external users using Excel to connect to SSAS cube. I understand the general concept that a cube user must be in a domain AD andthat same user is a member of a SSAS cube.
    How can I ensure the excel connection is secure and each external user is only able to view their own data? I know the workbook can be password protected but can the connection be also password protected ?
    BTW, I am not sure if this is the right forum for this question
    Regards

    Most modern external drives will typically go into a standby mode shortly after they're unmounted or disconnected which will spin down the drive. They'll still use some power, but your drive won't be doing anything so you don't need to worry about wearing it out. I'm a bit anal about stuff. I usually go so far as to unplug my external drives when I'm not using them as the power supply still consumes some juice... but, in your case, as it seems like you probably go back and forth quite a bit... just powering it down would be the best thing. It really doesn't take any extra effort when connecting your MacBook Pro to just switch it back on again.

  • How to establish the connection - Best Practice

    Following is my code for database connection
    import java.sql.Connection;
    import java.sql.DriverManager;
    import oracle.jdbc.driver.OracleDriver;
    public class DBConnect
         private static Connection connection = null;
         static
              try
                   DriverManager.registerDriver( new OracleDriver() );
                   String url = "jdbc:oracle:thin:@dbserver:1521:ORCL";
                   connection = DriverManager.getConnection( url, "user", "password" );
              catch ( Exception e )
         private DBConnect()
         public static synchronized Connection getConnection()
              return connection;
    }Tell me the Best Practice to establish the connection.
    Edited by: shashiwagh on Feb 1, 2010 11:25 AM
    Edited by: shashiwagh on Feb 1, 2010 11:26 AM

    First, handle your exceptions properly.
    Second, you should not normally create static database connections.
    Third, hardcoding connection data like that is not a good idea.

  • Access Connections best practice

    I like the idea of having Lenovo Access Connection change the appropriate settings depending on you network location. Like turning off wifi when you are cabled.
    Althoguh I often find it to be creating more problems than gains.
    Any generel best practice using this tool?
    Regards, Lars.

    Hi!
    Use non overlapping channel 1-6-11 on 3
    consecutive AP's.
    eg.
    AP1-Channel 1
    AP2-Channel 6
    AP3-Channel 11
    AP4-Channel 1
    AP5-Channel 6
    plzz take a look:
    http://www.cisco.com/en/US/products/hw/wirele
    ss/ps441/products_tech_note09186a00800a86d7.shtml#nonover
    HTH
    -Jai

  • Managed Bean Best Practices

    Hi
    Are there any best practices for using Managed Beans?
    We plan to use our own custom-built JSF components. Need to understand how to design backing beans for performance/effort optimization.
    For example :
    1. How to make managed beans thread-safe for concurrent requests, without compromising on efficiency/speed?
    2. How to enforce the J2EE security with managed-beans?
    3. How to decide the scope of these beans to ensure minimal data-storage in session?
    4. How to decide the granularity at which a managed-bean should be used for example :
    4.1 One bean-per-component
    Advantages :
    a) if complex components require special data-holding/processing/event-handling capabilities from bean
    (e.g. datagrid model,tree model,menu model)
    Problems :
    - with multiple components in a page/form
    a) it becomes tedious to debug/change/track which bean serves which component
    b) if session scope is required, too many beans will be cached in session
    c) unnecessarily too many beans will be created on server (= n pages * m components-per-page)
    d) unnecessarily increases the length of faces-config.xml
    4.2 One bean-per-form
    Advantages :
    a) in multi-form web pages, to ensure the functional behaviour of each form is separate/modular in its own bean.
    b) each managed-bean would map to specific/meaningful functionality/user-interaction in use-case.
    Problems :
    - if form includes complex components (datagrid/tree/menu) requiring a specialised bean class, then
    a) either one of the specialized bean has to be augmented with additional logic to handle data/events for all other components within the form
    (Not good, as it mixes-up the responsibilities of component-specific-beans, and the bean may no more be reusable in another form)
    b) or without using component-specific beans, only single form bean should handle the data/events for all components in the form?
    (Neither good, since if a complex tree-compoent is reused in multiple forms, then the logic to handle data/events for such a component will be repeated in those many form-specific managed beans)
    4.3 One bean-per-page
    Advantages :
    a) seems more modular/meaningful way - since a page would map to some feature within the use-case
    b) bean will contain only behaviour which is relevent for the associated page/function within use-case
    Problems :
    a) in multi-form pages, can single bean handle data/events for multiple forms?
    b) if page uses complex component (e.g datagrid, tree) that needs its own bean - how does page-bean exchange data with component-bean?
    Thanks,
    Arti

    Are there any best practices for using Managed
    Beans?There are no best practices for using Managed Beans in terms of Sun, or other vendors recommendations. But there are some patterns that can be applied to the managed beans (The managed bean is already a pattern). Also common sense is allways a good practice.
    For example, the managed bean should not have business logic code, only presentation logic code, etc.
    1. How to make managed beans thread-safe for
    concurrent requests, without compromising on
    efficiency/speed?The beans can be created by request, so concurrency is not an issue. If they are session scope, also is not an issue because, a user can only have one thread running. Only in application scope you must have carefull.
    >
    2. How to enforce the J2EE security with
    managed-beans?see this:
    http://jsf-security.sourceforge.net/
    About jsf-security
    >
    3. How to decide the scope of these beans to ensure
    minimal data-storage in session?If you wnat minimal data-storage in session the answer is request or none.
    In question 4, you make the question and give the answer ;-)

  • JSF DB Connection Best Practices

    During the life of a JavaServer Faces request, what are some best practices for storing a db connection?
    For the duration of the transaction, a single connection should be created before db updates, made available to (possibly) multiple model objects, and closed at the conclusion of the request. The connection would only live during the request.
    Right now each model object gets and releases it's own dbCon but that doesn't satisfy the (logical unit of work) requirements of a transaction when multiple objects are required for updating the database.
    What is a good technique to get a dbCon and release it, and, where should it be stored?
    TIA,
    Al Malin

    Hi,
    I'd like to ask a follow-up question.
    How do I close the connection after the session timed out or the user leaves the application by closing the browser?
    Thanks,
    Achim

  • Handling units management SAP Best Practices Document Links

    Hi Friends
    I would like know more about handling units management .
    Could you please send me  SAP Best Practices Document handling units management Links .
    Thanks in Advance.
    Thanks
    SR

    Might be useful:
    [Click here|help.sap.com/bp_bblibrary/500/documentation/U43_BB_ConfigGuide_EN_IN.doc|weblink]
    Thanks and Regards,
    Naveen Dasari.

  • Business Transaction Management (BTM) Best Practices Sharing

    A client I am working with is interested in building relationships with other Oracle customers using Business Transaction Management (BTM). The goal is to share tips, tricks, and best practices. BTM came from Oracle's acquisition of AmberPoint. Please contact me if you are interested in engaging. I can be reached at [email protected]

    Unless there is some other reason, users should own the right to share their mailboxes - it shouldn't be something that demands administrator management (if only so that the administrators aren't swamped by user requests for sharing their mailboxes). 
    For true shared mailboxes, when the mailbox is created, full access is granted by an administrator.

  • Physical Connection Best Practices

    Hi;
    I hope someone can help us.
    We already have 4 SG300 52 ports Switches: (L2 mode)
    We need to know the best way to connect the Switches and the router due to:
    - Do not get excesive latency in the internal network.
    - Do not get SPF problems.
    - Do not get duplicated pings
    - Get the maximum bandwith in the internal network.
    - Get the best router link.
    My thougts are:
    Option 1:
    Connect one uplink port to another uplink port at the next SW
    Connect the other uplink port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Option 2
    Connect two uplink ports to the two uplink ports at the next SW
    Connect the number 1 port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Option 3 
    Connect two uplink ports to the number 1 and 2 port at the next SW
    Connect the uplink port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Any suggestions?
    Thanks.
    Regards.

    If you have a multi-threaded server then before long you will have two "simultaneous" requests for a database connection. These requests will want to use different connections, since as you can see if they both use it at the same time, bad things will happen. You could synchronize so they wait in line to use the single connection but I think you can see that doesn't scale well to higher load.
    So you need to have access to more than one connection. What's commonly done in multi-threaded servers is to use a connection pool. You can get open-source connection pools, so don't spend any time writing your own. (They aren't easy to get right.)

  • Closing DB Connection-Best Practice

    Currently I am opening and closing my connection to the database on each event that warrants a database connection. Is this the way I should handle it, or should I open the connection at the beginning and close it at the end, leaving it open in between?
    I have a certain panel that has numerous, separate inputs to a database that are isolated from each other, and if I happen to use all of these inputs, I open and close the connection 3 or 4 times.
    Thanks

    Hi,
    As far as an application is concerned we usually wont advice opening and closing connection as and when necessary. But if the connection is open for a long time there are some possible problems. One is that if the server goes down the user wont be aware of that till he executes the next query and also the error wont will be a valid one.Next is the amount of time ther server holds the connection and this has its significance if max. number of connections is specified.
    So again, its upto you to decide what all conditions are applicable to you. Its actually a trade-off between reliability and performance. :-)..
    regards Stallon

  • Intangible item management & SAP best practice

    All,
    I am wondering what is the best way to handle intangible flow within SAP.
    As a definition, intangible Items are any kind of assets or products that cannot be touched. As an exemple, it can be software / License / License keys. In this question, I am referring to intangible items that are mostly considered as Asset (meaning not standard cost exist for the intangible item).
    Thanks,

    Hi,
    As you wrote, you maintain intangible items as Assests in FI. You can then run depreciation from FI-AA moldule.
    Regards,
    Marcin

  • Sql connection best practices

    Can someone discuss the pros and cons of setting your db connection in the web.xml and then using the following in a jsp;
    <sql:query var="myQuery">
         SELECT * FROM mytable
    </sql:query>I find that it is quick and easy, but would I want to give this kind of code to my supervisor? From 20,000 ft up. :)
    Edited by: Reme on Aug 2, 2008 5:12 AM

    [http://java.sun.com/javaee/5/docs/tutorial/doc/bnald.html]
    The JSTL SQL tags for accessing databases listed in Table 7-7 are designed for quick prototyping and simple applications. For production applications, database operations are normally encapsulated in JavaBeans components.I wouldn't use it. Layer your application properly. Make use of a DAO class.

  • What is the best practice to connect 2 sites and replicate ADDS between 2 different sites using windows server 2012 r2?

    I found that there is new features remote access inside windows server 2012 r2 which is much more easier. Is there anybody can suggest me how to connect 2 different sites and it will be the tunnel to replicate ADDS (RW) between both sites.

    See this
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/133e7780-6a59-4bd7-906b-70830bea48d0/sites-connections-best-practice?forum=winserverDS
    Regards,
    Biswajit
    MCTS, MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, Enterprise Admin, ITIL F 2011
    Blog:
      Script Gallary:
      LinkedIn:
    Note: Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights..

  • SAP Best Practice Integrated with Solution manager

    We have a server in which we installed SAP Best practice baseline package and we have the solution manager 7.01 SP 25
    We maintained the logical port but when we try to check connectivity to solution manager we got the following error:
    Connectivity check to sap solution manager system not successful
    Message no. /SMB/BB_INSTALLER375
    Can anyone guide us how to solve the problem and also if there is another way to upload the solution defined on the best practice solution builder into sap solution manager as a template project
    Thanks,
    Heba Hesham

    Hi,
    Patches for SAPGUI 7.10 can be found at the following location:
    http://service.sap.com/patches
    -> Entry by Application Group -> SAP Frontend Components
    -> SAP GUI FOR WINDOWS -> SAP GUI FOR WINDOWS 7.10 CORE
    -> SAP GUI FOR WINDOWS 7.10 CORE -> Win 32
    -> gui710_2-10002995.exe

  • [XI 3.1] BEST PRACTICE method of Oracle connection for RPTs on Linux

    Business Objects XI (3.1) - SP3.
    Running on Red Hat Enterprise Linux OS.
    7,000+ Crystal Reports 2008 *.rpt objects ONLY (No Universe / No WebI).
    All reports connecting to Oracle 10g databases.
    ==================
    In the past, all of this infrastructure was running on Windows Server OS and providing the database access via a Named ODBC connection (eg. "APP_DATA".)
    This made it easy to manage as all the Report Developers had a standard System DSN called "APP_DATA" which was the same as the System DSN name on all of our DEV, TEST/UAT, and PROD servers for Business Objects.
    When we wanted to move/promote a *.rpt file from DEV to PROD we did not have to change any "Database Connection" info as it was all taken care of by pointing the System DSN called "APP_DATA" a a different physical Oracle server at the ODBC level.
    Now, that hardware is moving from Windows OS to Red Hat Linux and we are trying to determine the Best Practices (and Pros/Cons) of using one of the three methods below to access the Oracle database for our *.rpts....
    1.) Oracle Native connection
    2.) ODBC connection
    3.) JDBC connection
    Here's what we have determined so far -
    1a.) Oracle Native connection should be the most efficient method of passing SQL-query to the DB with the fewest issues and best speed [PRO]
    1b.) Oracle Native connection may not be supported on Linux - http://www.forumtopics.com/busobj/viewtopic.php?t=118770&view=previous&sid=9cca754b468fc67888ab2553c0fbe448 [CON]
    1c.) Using Oracle Native would require special-handling on the *.rpts at either the source-file or the CMC level to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    2a.) A 3rd-Party Linux ODBC option may be available from EasySoft - http://www.easysoft.com/products/data_access/odbc_oracle_driver/index.html - which would allow us to use a similar Developer / Admin overhead to what we are used to. [PRO]
    2b.) Adding a 3rd-Party Vendor into the mix may lead to support issues is we have problems with results or speeds of our queries. [CON]
    3a.) JDBC appears to be the "defacto standard" when running Oracle SQL queries from Linux. [PRO]
    3b.) There may be issues with results or speeds of our queries when using JDBC. [CON]
    3c.) Using JDBC requires the explicit-IP of the Oracle server to be defined for each connection. This would require special-handling on the *.rpts at either the source-file (and NOT the CMC level) to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    ==================
    We would appreciate some advice from anyone who has been down this road before.
    What were your Best Practices?
    What can you add to the Pros and Cons listed above?
    How do we find the "sweet spot" between quality/performance/speed of reports and easy-overhead for the Admins and Developers?
    As always, thanks in advance for your comments.

    Hi,
    I just saw this article and I would like to add some infos.
    First you can quite easely reproduce the same way of working with the odbc entries by playing with the oracle name resolution on the server. By changing some files (sqlnet, tnsnames.ora,..) you can define a different oracle server for a specific name that will be the same accross all environments.
    Database name will be resolved differently regarding to the environment and therefore will access a different database.
    Second option is the possibility to change the connection in .rpt files by an automated way like the schedule manager. This tool is a additional web application to deploy that can change the connection settings of rpt reports on thousands of reports in a few clicks. you can find it here :
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80af7965-8bdf-2b10-fa94-bb21833f3db8
    The last option is to do it with a small sdk script, for this purpose, a few lines of codes can change all the reports in a row.
    After some implementations on linux to oracle database I would prefer also the native connection. ODBC and JDBC are deprecated ways to connect to database. You can use DATADIRECT connectors that are quite good but for volumes you will see the difference.

Maybe you are looking for