Created
August 1, 2019 04:47
-
-
Save ksoumi/6325265006e0270ec27138f2e0d1151d to your computer and use it in GitHub Desktop.
Database Connection MySQL
This file contains 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 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