Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- public class Database {
- private static final String URL = "jdbc://localhost/football";
- private static final String USER = "root";
- private static final String PASSWORD = "";
- private static Connection connection = null;
- private Database() { }
- public static Connection getConnection() throws SQLException {
- if (connection == null) {
- createConnection();
- connection.setAutoCommit(false);
- }
- return connection;
- }
- public static void createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection(URL, USER, PASSWORD);
- } catch (ClassNotFoundException e) {
- System.err.print("ClassNotFoundException: " + e);
- } catch(SQLException e) {
- System.err.println("SQLException: " + e);
- }
- }
- public static void closeConnection() {
- try {
- connection.close();
- } catch (SQLException e) {
- System.err.print("D: " + e);
- }
- }
- public static void commit() {
- try {
- connection.commit();
- } catch (SQLException e) {
- System.err.print("D: " + e);
- }
- }
- public static void rollback() {
- try {
- connection.rollback();
- } catch (SQLException e) {
- System.err.print("D: " + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement