title: How can I use one database connection object in whole application?
body: <p>I have created this class which returns connection object. I have used MySQL database.</p>
  
  <pre><code>public class Connect_db {        
      public Connection getConnection(String db_name,String user_name,String password)
      {
          Connection con=null;
          try
          {
          Class.forName("com.mysql.jdbc.Driver");
          con=DriverManager.getConnection("jdbc:mysql://localhost/"+db_name+"?user="+user_name+"&amp;password="+password);
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
  
          return con;        
      }
  }  
  </code></pre>
  
  <p>Now all I want to do is instantiate this class once and get connection object.
  And I want to use this same object in entire application.
  Another solution will also be appreciated.</p>