Skip to content

Instantly share code, notes, and snippets.

@ksoumi
Created August 1, 2019 04:47
Show Gist options
  • Save ksoumi/6325265006e0270ec27138f2e0d1151d to your computer and use it in GitHub Desktop.
Save ksoumi/6325265006e0270ec27138f2e0d1151d to your computer and use it in GitHub Desktop.
Database Connection MySQL
package io.pivotal.workshop.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SingleDatabaseConnection {
private static Connection connection = null;
static String url = "jdbc:mysql://localhost:3306/userdb";
static String user = "root";
static String password = "root";
static {
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(url,user,password);
} catch (SQLException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private SingleDatabaseConnection() {
super();
}
public static Connection getConnection() {
return connection;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment