View Javadoc

1   package migratool.access;
2   
3   import java.sql.Connection;
4   import java.sql.DriverManager;
5   import java.sql.SQLException;
6   
7   import migratool.model.BDdescription;
8   
9   /**
10   * 
11   * MIGRATOOL Program to migrate spatial databsets.
12   * Copyright (C) 2007 Fábio Luiz Leite Júnior
13   * Universidade Federal de Campina Grande
14   * contact: fabioleite@gmail.com
15   *
16   * This program is free software; you can redistribute it and/or
17   * modify it under the terms of the GNU General Public License
18   * as published by the Free Software Foundation; either version 2
19   * of the License, or (at your option) any later version.
20   *
21   * This program is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24   * GNU General Public License for more details.
25   *
26   * You should have received a copy of the GNU General Public License
27   * along with this program; if not, write to the Free Software
28   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
29   *
30   * @author fabio
31   *
32   */
33   
34  public class Connector {
35  	
36  	/** Singleton */
37  	private static Connector singleton;
38  
39  
40  	private Connector(){
41  	}
42  
43  	/**
44  	 * M�todo que retorna a inst�ncia do Singleton
45  	 * @return Uma f�brica de Formatters SVG
46  	 */
47  	public static Connector getInstance() {
48  		if (singleton == null)
49  			singleton = new Connector();
50  		return singleton;
51  	}
52  	
53  	public Connection getConnection(BDdescription description) {
54  		Connection con = null;
55  		try {
56  			Class.forName(description.getDriver());
57  			con = DriverManager.getConnection(description.getUrl(),
58  												  description.getUser(),
59  												  description.getPassword());
60  		} catch (ClassNotFoundException e) {
61  			e.printStackTrace();
62  		} catch (SQLException e) {
63  			e.printStackTrace();
64  		}
65  	
66  		return con;	
67  	}
68  	  
69  }