Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mandacaru3.dao;
- import java.io.InputStream;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.Properties;
- public class ConnectionFactory {
- private static Connection connection = null;
- public static Connection getConnection() {
- if (connection != null)
- return connection;
- else {
- Properties prop = new Properties();
- InputStream inputStream = ConnectionFactory.class.getClassLoader().getResourceAsStream("db.properties");
- try {
- prop.load(inputStream);
- String url = prop.getProperty("url");
- String user = prop.getProperty("user");
- String password = prop.getProperty("password");
- connection = DriverManager.getConnection(url, user, password);
- return connection;
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return null;
- }
- public static void disconnect() {
- try {
- connection.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement