Question regarding Database Connection.

Normally, after we open a database connection, we could use the Connection.close() method to close and return database connection back to a connection pool.
What would happen if I nullify the connection without using the close() method to close a database connection?
Would the database connection automatically close after I nullify it?
If not, how the connection going to return back to the connection pool?

The connection will close/be released automatically when the garbage collector runs, but you should NEVER rely on that because you never know when the GC will run or if it will collect all objects or only part of them. Best approach is to always have a finally block where you close/release the connection.
Alin.

Similar Messages

  • Design question for database connection in multithreaded socket-server

    Dear community,
    I am programming a multithreaded socket server. The server creates a new thread for each connection.
    The threads and several objects witch are instanced by each thread have to access database-connectivity. Therefore I implemented factory class which administer database connection in a pool. At this point I have a design question.
    How should I access the connections from the threads? There are two options:
    a) Should I implement in my server class a new method like "getDatabaseConnection" which calls the factory class and returns a pooled connection to the database? In this case each object has to know the server-object and have to call this method in order to get a database connection. That could become very complex as I have to safe a instance of the server object in each object ...
    b) Should I develop a static method in my factory class so that each thread could get a database connection by calling the static method of the factory?
    Thank you very much for your answer!
    Kind regards,
    Dak
    Message was edited by:
    dakger

    So your suggestion is to use a static method from a
    central class. But those static-methods are not realy
    object oriented, are they?There's only one static method, and that's getInstance
    If I use singleton pattern, I only create one
    instance of the database pooling class in order to
    cionfigure it (driver, access data to database and so
    on). The threads use than a static method of this
    class to get database connection?They use a static method to get the pool instance, getConnection is not static.
    Kaj

  • Question regarding ONT connection via Ethernet and Cable cards

    Hi,
    We recently upgraded to Fios Quation 150Mbps/65  plan. We are not getting the advertised speeds (we only get like 5mbps upload) so verizon is sending a tech to switch the ONT connection from coax to ethernet.
    I have 2 questions regarding this new setup:
    1. If the ONT communicates with the Fios Actiontect router via ethernet instead of coax from now on, How will the set top boxes and Tivo-esque cable card powered device I currently have connected to coax, talk to the verizon system from now on, if coax is taken out of the equation? Will fios signal still flow through the internal coax wiring of the house? And moreover, I was under the impression that coax was the way set top boxes communicated and derived independent ip addresses from the Fios router, for on deman purposes and what not. How will this work from now on?
    Quiestion 2.
    Right next to the wall where the ONT sits, theres's a basement office where we have a PC that connects to the Fios system  via an Actiontect MoCa adapter (ECB2500C) which I assume derives it internet connection from the Fios Actiontec router which sits upstairs in the living room. 
    Again, with the Coax about to be disabled next Friday in favor of ethernet connection from the ONT, I assume this PC will be left without internet because of the lack of internet signal in the coax? Is this correct? 
    Question 2.5 If my above assumption is correct, since this office is right on the other side of the wall where the ONT sits outside the house, would it be possible to run an ethernet wire through the wall that connects straight from the ONT to an ethernet switch inside the office, from which I would derive a connection for this basement PC (properly firewalled of course) and then, from said switch, continue running the ethernet wire that would ultimately reach the Actiontec Fios router upstairs from which the rest of the house derives it's internet?  and would this setup affect in any way the propper functioning of the cable boxes in the house?
    I'd appreciate your input and any help you can provide so I can have a ballpark idea of what to tell the Fios guy to do when he comes on Friday.
    Cheers.
    Solved!
    Go to Solution.

    It's not valid to have two devices connected to the ONT, PC and VZ Router.  Must be a single device. The ONT locks onto the MAC Address of the first device it sees. Since you have TV you should have the VZ router as the internet facing router.
    Other options:
    1.  Have the VZ Router located next to the PC in the basement and then use Wireless for all other PC's.
    2.  Have the VZ Router located next to the PC in the basement but run one wire upstairs and connect a switch where other PCs and devices can connect via a wire.
    Hope that helps.

  • Brand newbie question on database connection

    I'm brand new to Oracle databasing and am having trouble figuring out how to set up a connection to an existing database. Specifically, I'm not clear at all about the use of the tnsname.ora file. What I'm trying to do is set up a connection using an .asp page to connect to this database. I'm using :
         objConnect.Open ("Provider=MSDASQL;DRIVER={Microsoft ODBC for Oracle};Server=F12_PROD_MARS.WORLD;UID=FLGI;PWD=FLGI")
    [/CODE]
    Which gives me the "ORA-12154: TNS:could not resolve service name" error. I know the information that I need in my tnsname.ora file is:F12_PROD_MARS =
    (DESCRIPTION=
    (ADDRESS_LIST=
    (ADDRESS=
    (PROTOCOL=TCP)
    (Host=172.31.xx.xx)
    (Port=1521)
    (ADDRESS=
    (PROTOCOL=TCP)
    (Host=172.31.xx.xx)
    (Port=1526)
    (CONNECT_DATA=
    (SID=MARS)
    I don't know where the tnsname.ora file is supposed to be located or how to reference it from .asp or anything like that though. The only database connection experience I have is with my own access databases, but none trying to connect to someone elses oracle db. Any help at all or a link to some kind of starters guide would be much appreciated. Also, I downloaded pl/sql developer, but I cannot log on to that either. I don't know if its the same connection issue here, but I know my user/pass for the server is correct, what do I enter for database, so that the application knows where to go? Thanks again... -ST

    objConnect.Open ("Provider=MSDASQL;DRIVER={Microsoft
    t ODBC for
    Oracle};Server=F12_PROD_MARS.WORLD;UID=FLGI;PWD=FLGI")I take it you have the Oracle Client installed on the web app server i.e. where the MS ODBC driver lives
    ODBC now looks for tns name "f12_prod_mars.world" ...
    Which gives me the "ORA-12154: TNS:could not resolve service name" error.
    I know the information that I need in my tnsname.ora file is:
    F12_PROD_MARS =
    ... because it looks for that name, including .world, and cant find it. Name "f12_prod_mars" is not the same name, obviously. (like test.com and test.se are different)
    I don't know where the tnsname.ora file is supposed
    to be located or how to reference it from .asp orWhere is it located now? If you search the harddrives for tnsnames.ora, what do you get?
    connection issue here, but I know my user/pass for
    the server is correct, what do I enter for database,
    so that the application knows where to go? ThanksIf an app, like sql*plus, is asking for "Database:" it often means you give the tns name (=the alias for the tns connect descriptor, which is the thing with lots of ('s and )'s) :)
    Message was edited by:
    orafad

  • [Help] Regarding database connection!

    Hi , i am new to dreamweaver, I have started working on a website, the designing part is completed. I am now trying to connect database through dreamweaver to mysql. As i said I am new to this, I have created four pages, all of which are in .html format. When i  try to connect to a database, it needs me o choose from .php or dotnet.
    So, here is my question do I need to shift my work to dotnet or php? As i dont know php so i am taking dotnet
    2ndly how can I connect to a database? All schemas are defined! Which files do i need to change if i want a registration page to connect to database??
    Please Help!

    If you want to connect your website to a database, it's advisable to change the filename extension of all pages from .html to the server-side technology of your choice. Before making your choice, you might find the following article helpful: Which server-side technology should I choose?
    If you decide on .NET, you should be aware that Dreamweaver has no support for it.
    Dreamweaver has extensive support for PHP, but I wouldn't recommend using Dreamweaver's built-in server behaviors to connect to a database. They rely on outdated code, and are not recommended for use in a live website.
    If you want to set up Dreamweaver to work with PHP, instructions for doing so are in the following article: http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html.

  • A question regarding database table partitioning and table indexes in 10g

    We are considering partitioning a large table in our 10g database, in order to improve response time. I believe I understand the various partitioning options, but am wondering about the indexes built over the table. When the table is partitioned, will the indexes also be partitioned "automatically"? Or do I need to also partition the indexes as well?
    Thank you in advance to any and all who respond to this question.

    Hello,
    When you build your partiton table you just need to create indexes locally and they will be partitioned automatically, see following example
    CREATE TABLE YY_EVENT
      PART_KEY       DATE                              NOT NULL,
      SUBPART_VALUE  NUMBER                             NULL,
      EVENT_NAME     VARCHAR2(30 BYTE)                  NULL,
      EVENT_VALUE    NUMBER                             NULL
    TABLESPACE TEST_DATA
    PARTITION BY RANGE (PART_KEY)
      PARTITION Y_EVENT_200901 VALUES LESS THAN (TO_DATE(' 2009-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
        TABLESPACE TEST_DATA, 
      PARTITION Y_EVENT_200902 VALUES LESS THAN (TO_DATE(' 2009-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
        TABLESPACE TEST_DATA
    -- This will create paritioned indexes automatically
    CREATE INDEX MY_IDX ON YY_EVENT
    (EVENT_NAME)
      TABLESPACE TEST_DATA
    LOGGING
    LOCAL;Regards
    Edited by: OrionNet on Feb 25, 2009 12:05 PM

  • Need help urgent!! regarding Database connection failure

    Hi Experts,
    when i try to login sqlplus...i came across with this error 'TNS adaptor error'
    as i try to restart the services i dont have the sufficient privilages to start.
    Mean while, i have another database in my another system. i know the port number ,host name and all...
    can i connect from one system to another using the port number,host name..
    If So, can any one help me pls

    Hi Bhargav,
    check $ORACLE_HOME $PATH and $ORACLE_SID is correct?
    what OS? windows need service privileges, contact admin.
    can i connect from one system to another using the port number,host name..yes, and login info.
    --sgc                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help regarding database connection

    hello
    iam new to j2ee i am using Jsp,Ejb and Jboss server i need to connect to the oracle database with the above configuration wher can i find the tutorials can anybody help me please

    a word of advice - if you're new to jsp, jboss, and ejbs, and obviously know nothing about jdbc either, this isn't the way to learn it.
    start with the jdbc tutorial and see if you can get a single java class to connect to a database and execute some sql. then work up from there.
    what you're doing is something known as "biting off more than you can chew".
    %

  • Question about Database Access

    Hello,
    I have one question regarding database access from Java.
    What are the other ways of connecting to database other than JDBC? This was one of the question I been asked by the interviewer. He says JDBC connection can slow down the perfomance when it comes large number of transactions?
    Any insight or help will be very useful.
    Thanks

    He may have been referring to available "persistance managers" like Hibernate or the mechanisms build into EJB containers. However, as far as I know, they all use JDBC, and any speed-up is due to caching of data as objects.

  • Database connection closing in JSF

    This is regarding Database connection closing in JSF.
    in servlets we have destroy method where we will be closing the database connections, similarly in JSF where should we close the database connections? is it taken care by the framework?
    is there a way where we could capture the end of session and then close the database connection?
    I am creating database connection in backing bean as I am not supposed to create a pool of connection objects(I am using tomcat 5.5)
    Thanks in advance for any suggestions about this.

    k_srinivas wrote:
    This is regarding Database connection closing in JSF.OK.
    in servlets we have destroy method where we will be closing the database connectionsThis is at its own already a very bad practice. All database resources like Connection, Statement and ResultSet must be acquired and closed in the shortest possible scope. You should never keep them open as an instance variable and for sure not in a servlet (which lives as long as the application lives). If you keep a connection open that long, it will timeout sooner or later and your application will crash.
    , similarly in JSF where should we close the database connections? is it taken care by the framework?
    is there a way where we could capture the end of session and then close the database connection?No, just acquire and close the resources in the shortest possible scope. To improve performance, introduce connection pooling. But this doesn't mean that you can write the JDBC code the other way. You still need to acquire and close the resources quickly. The connection pooling implementation will worry about actually closing the connection or releasing the connection to the pool.
    I am creating database connection in backing bean as I am not supposed to create a pool of connection objects(I am using tomcat 5.5)
    Thanks in advance for any suggestions about this.This makes no sense. Just make use of Tomcat's own connection pooling facility.
    For more about doing the database access logic the proper way, you may find this tutorial useful: [http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html].

  • Questions regarding Connection Pooling

    Hi
    i have some confusion regarding how connection pooling is implemented..i have been doing some digging in to this lately but the more i read the more confused i get. i have some doubts here, will any of the posters here kindly clear them
    a. Do i have to connect to my database via the DataSource method to take advantage of the connection pooling provided by my app server?..i have read conflicting information about this suggesting that Connection Pooling will not be provided to my app if i use DriverManager.getConnection()
    b. if i chose to use the DataSource method do i have to implement the ConnectionPoolDataSource interface to provide the connection pooling for my app?
    c. what is the best way to implement my own custom Connection pool?
    Thanx

    DriverManager.getConnection() literally creates, that is, builds a connection to the database using the values you previously supplied when you loaded the driver.
    A connection pool is an object that contains several already made connections to the database, and simply provides you with one of those existing connections. The confusion arises because a) the method name is frequently the same and b) the connection pool object calls the driver's getConnection() method to create several connections before lending any of them out.
    In other words:
    DriverManager.getConnection() builds a connection to the database.
    ConnectionPool.getConnection() fetches an existing connection.
    So, to answer your questions...
    A. This is correct. If you use DriverManager.getConnection(), you are indeed bypassing the Connection Pool entirely.
    B. I'm not familiar with DataSource specifically, but in general, a third party connection pool will either give you the interface (and you implement the details) or they will give you the class file containing the DataSource object. All you would have to do in the latter case is to import that file, then create a new instance of it using the new keyword ( DataSource foo = new DataSource(); ). I suspect DataSource is indeed the class file.
    C. Creating a connection pool is trivial and there are many examples of it - search on this forum or check out your favorite Java/JDBC programming book. Usually, the question "Should I use a connection pool and why?" is a more important question.

  • Questions regarding creating the database

    Hi there,
    From the previous posting, http://forum.java.sun.com/thread.jspa?threadID=640415&tstart=15 someone gave me the "formula" of connecting to the database:
    java.sql.Connection  conn   =  java.sql.DriverManager.getConnection("jdbc:mysql://localhost/name_of_DB","user","password") Now just couple of questions regarding the formula :
    1) Obviously, if I want the name of my DB, then I will have to create my DB. Can somebody please tell me the protocol of creating the DB? And where do I create this DB (i.e can I create it anywhere in my application)? Or is it that I have to create a new database using MySQL itself?
    2) After creating a database, I would like to create multiple tables containing different datas. Is it possible to place the code creating these tables anywher in the application I want?
    Your ideas or advice would be much appreciated. Thank you in advance.
    Regards,
    Young

    1) Yes, you'll have to create the database using MySQL.
    2) You sure can once you have the database created with the proper rights assigned to your user. You can put the code anywhere you want but you may want to put it somewhere where it only ran once like on install if you're doing a standalone app.

  • Question regarding Polling data from database using DB Adapters in BPEL

    Hi,
    I have the following question regarding Polling data from database using DB Adapters in BPEL -
    If I am selecting data from multiple tables/view to ultimately generate hierarchical xml document, is there a way that I specify polling all of these tables/views. Is polling limited only to one table/view?
    Thanks
    Ravi

    Hi Ravi,
    your question seems to have been answered for the question of polling a set of tables with one as the root, and getting back a hierarchical xml representing multiple related tables.
    However you can also poll for changes to both the root table and its related tables. Not sure if this was your question or the one already answered. If the former please check out the sample
    bpel/samples/tutorials/122.DBAdapter/advanced/polling/PollingForChildUpdates
    Thanks
    Steve

  • ODI database connection - session question

    Hi,
    I have a package, where I have used a procedure.
    In my procedure, I open a database connection.
    My question is - In my next procedure - will I be able to use my same database connection which I created in previous step?
    Re-phrasing the question - for any number of database transaction happening in a package, will ODI opens multiple database connection per step or will there be only one single database connection?
    Thank you,
    Paras

    I believe its one per session so one connection inside the package. I think you should be , although i have not tried it practically.

  • Database Connection design question

    Hello, I have a design question. Awhile back I needed to create a database connection to SQL Server, so I created a class to do it
    import java.sql.*;
    import java.io.*;
    import java.net.MalformedURLException;
    import org.w3c.dom.Document;
    import org.w3c.dom.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    public class SQLServerConnection
         private static Connection connection = null;
         public SQLServerConnection(String user, String password, String dbName) throws java.sql.SQLException
              getDBConnection(user, password, dbName);
         public SQLServerConnection(String configFileName) throws java.sql.SQLException
              getDBConnection(configFileName);
         private void getDBConnection(String user, String password, String dbName) throws java.sql.SQLException
             DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
             connection = DriverManager.getConnection(
                  "jdbc:microsoft:sqlserver:" + dbName, user, password);              
         private void getDBConnection(String configFileName) throws java.sql.SQLException
              String user;
              String password;
              String dbName;
              try
                   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                   DocumentBuilder db = factory.newDocumentBuilder();
                   Document doc = db.parse(configFileName);
                   doc.getDocumentElement().normalize();
                   // get the configuration information
                   password = getConfigParameter("password", doc);
                   user = getConfigParameter("username", doc);
                   dbName = getConfigParameter("databasename", doc);
                   getDBConnection(user, password, dbName);
              catch (MalformedURLException murle)
                   System.out.println("Unable to connect to: " + configFileName + " -- " + murle);
                   System.exit(1);
              catch (FileNotFoundException fnfe)
                   System.out.println("Configuration file " + configFileName + " not found.");
                   System.exit(1);
              catch (IOException ioe)
                   System.out.println("IOException: " + ioe);
                   System.exit(1);
              catch (javax.xml.parsers.ParserConfigurationException pce)
                   System.out.println ("Parser Configuration Error: " + pce);
              catch (SAXException saxe)
                   System.out.println ("SAXException: " + saxe);
         private String getConfigParameter(String paramName, org.w3c.dom.Document doc)
              NodeList nl = doc.getElementsByTagName(paramName);
              if(nl != null)
                   Node n = null;
                   for (int i = 0; i < nl.getLength(); i++)
                        n = nl.item(i);          
                        if(n.hasChildNodes())
                             NodeList children = n.getChildNodes();
                             return ((Node)children.item(0)).getNodeValue();
              else
                   System.out.println ("nl is null");
              return "";          
         public void setCatalog(String catalogName) throws java.sql.SQLException
              connection.setCatalog(catalogName);
         public Connection getConnection()
              return connection;
         public void closeConnection()
              try
                   connection.close();
              catch(java.sql.SQLException sqle)
                   System.err.println ("SQL Server Connection failed to close: " + sqle);
    }Later on, I needed to do the same thing for MySQL, so I created a class for that, MySQLServerConnection which is exactly the same as above, except for:
    private void getDBConnection(String user, String password, String dbName) throws java.sql.SQLException
              try
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
                   connection = DriverManager.getConnection(dbName, user, password);     
              catch(java.lang.ClassNotFoundException cnfe)
                   System.out.println (cnfe);
              catch(java.lang.InstantiationException ie)
                   System.out.println (ie);
              catch(java.lang.IllegalAccessException iae)
                   System.out.println (iae);
         }Later, on, I did the same thing with OracleServerConnection. My question is, I know this is probably not optimal code. For example, I didn't originally have a close connection method, so I had to go in and code one for all 3. I'm assuming that an interface would be a good idea so that if I have to code another database connection class I make sure and include all of the appropriate methods. I'm also assuming that it would have been smart to have a master class, maybe something like DatabaseConnection and extended these classes from that. Am I on the right track? Totally offbase?

    @nclow - I will work on trying the Factory Pattern for this over the weekend and post when I finish to see what you think.
    @abillconsl - just to make sure I understand, you're saying that I just try to connect and it will cycle through the different database connection possibilities and connect when it finds the right one? If it fails all 3, log an appropriate message. One question I have about this is, I thought I was being object oriented by separating the different types of db connections (Oracle, SQL Server, MySql) into different classes. Am I missing the point of OOP by what I was/am trying to accomplish? Going overboard? Also, does your way try and connect to all 3 even if I connected to one already?
    Thx, Grantarchy
    Edited by: grantarchy on May 9, 2008 9:50 PM

Maybe you are looking for

  • Dunning Related Issue

    Dear All,   I have configured Dunning for my company and for the first Dunning Level 1 the dunning is running sucessfully, no issues..   But when Iam running for the Dunning Level 2 I am unble to get a print out the log that has been displayed is Dun

  • Error while deploying to remote server

    Hi, I'm trying to deploy an application from Java Studio Creator2 (running in my home office) to a Java System Applicatio Server PE 8.2 (running in our company). The server is behind a NAT router an has a private IP address on the company LAN (10.0.0

  • The audio is not working

    I have a HP Pavilion dv6 with windows 7 64bit system.  everything was working fine untill the audio just quite. trouble shooting shows the drivers workin properly No error msg, no sound    This question was solved. View Solution.

  • Pdf to word question (Acrobat 7 pro)

    Hello, I am trying to conver a pdf file to a word file. What I want is Acrobat converts each pdf page as an image on a separate page in the word file. I noticed Acrobat always tris to convert pdf to editable text, only when that failes, it resorts to

  • Anyone else have this problem?

    Hi all, I am using JDeveloper 10.1.3.3 with ADF and BC. My team and I have been experiencing "interesting" problems with the IDE. The first issue is with a right click, the application sometimes closes. What could be causing this? It happens seemingl