Created
June 30, 2021 01:48
-
-
Save jeffersonchaves/cc48489ab934d138594ddba10f868619 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package database; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.SQLException; | |
public class ConnectionFactory { | |
private static Connection connection; | |
/*Singleton*/ | |
public static Connection getConnection() { | |
if(connection == null) { | |
try { | |
//necessário para aplicacões web | |
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver()); | |
connection = DriverManager.getConnection("jdbc:mysql://localhost/if_delivery", "root", "root"); | |
} catch (SQLException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
return connection; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment