Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package daoaluno;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class ConnectionFactory {
- String driverClassName = "com.mysql.jdbc.Driver";
- String connectionUrl = "jdbc:mysql://localhost:3306/exemplo_jdbc";
- String dbUser = "root";
- String dbPwd = "vertrigo";
- private static ConnectionFactory connectionFactory = null;
- private ConnectionFactory() {
- try {
- Class.forName(driverClassName);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public Connection getConnection() throws SQLException {
- Connection conn = null;
- conn = DriverManager.getConnection(connectionUrl, dbUser, dbPwd);
- return conn;
- }
- public static ConnectionFactory getInstance() {
- if (connectionFactory == null) {
- connectionFactory = new ConnectionFactory();
- }
- return connectionFactory;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement