Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package medivation.domain.JavaClasses;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- * Created by c1324725 on 29/11/2016.
- */
- public class ConnectionManager {
- private static String url = "jdbc:mysql://localhost:3306/medivation";
- private static String driverName = "com.mysql.jdbc.Driver";
- private static String username = "root";
- private static String password = "abc123";
- private static Connection con;
- public static Connection getConnection() {
- try {
- Class.forName(driverName);
- try {
- con = DriverManager.getConnection(url, username, password);
- } catch (SQLException ex) {
- // log an exception. fro example:
- System.out.println("Failed to create the database connection.");
- }
- } catch (ClassNotFoundException ex) {
- // log an exception. for example:
- System.out.println("Driver not found.");
- }
- return con;
- }
- public static void closeConnection(){
- try {
- if(con != null)
- {
- con.close();
- System.out.println("Connection closed");
- }else {
- System.out.println("Connection already closed");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement