title: How to use Singleton class for to get connections multiple?
body: <p>I wrote a Singleton class for  getting connections. However, I cannot get connections using Singleton.</p>
  
  <p>I want to use my Singleton for getting several connections and to make query to database, using the connection Singleton. I always try several ways for this, and no success.</p>
  
  <p>This is my Singleton class:</p>
  
  <pre><code>import java.sql.*;
  
  public class ConnectDB {
  
  private static Connection connect;
  private static ConnectDB instance;
  
  private ConnectDB()
  {
  
      try {
  
          Class.forName("com.mysql.jdbc.Driver");
          //connect DB
          connect = DriverManager.getConnection("jdbc:mysql://ip/database","root","password");
  
      }
  
      catch(SQLException e)
      {
          System.err.println(e.getMessage());
  
      }
  
      catch(ClassNotFoundException e)
      {
  
          System.err.println(e.getMessage());
  
      }   
  }
  
    public static ConnectDB getInstance()
    {
  
        if(instance == null) {
  
            instance = new ConnectDB();
  
        }
  
        return instance;
  
    }
  
  }
  </code></pre>
  
  <p>Now, I get the connections:</p>
  
  <pre><code> public class NameClass {
  
  
  
  
  public void getInfoDatabase()
  {   
  
         Connection cnn = ConnectDB.getConnection();
         PreparedStatement ps;
         ResultSet rs;
  
         try {
  
             ps = cnn.prepareStatement("select *  from tables");
  
             rs = ps.executeQuery();
  
             while(rs.next())
             {
  
                 String tables = rs.getString("table1");
                 System.out.println(tables);
             }
  </code></pre>