Skip to content

Instantly share code, notes, and snippets.

@jeffersonchaves
Created June 30, 2021 01:48
Show Gist options
  • Save jeffersonchaves/cc48489ab934d138594ddba10f868619 to your computer and use it in GitHub Desktop.
Save jeffersonchaves/cc48489ab934d138594ddba10f868619 to your computer and use it in GitHub Desktop.
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