Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package crudapp;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.SQLException;
  11.  
  12. /**
  13.  *
  14.  * @author robin
  15.  */
  16. public class ConnectionManager {
  17.  
  18.     String dbURL = "jdbc:mysql://localhost:3306/SampleDB";
  19.     String username = "root";
  20.     String password = "root";
  21.  
  22.     public Connection getConnection() {
  23.         Connection conn = null;
  24.         try {
  25.  
  26.             conn = DriverManager.getConnection(dbURL, username, password);
  27.  
  28.             if (conn != null) {
  29.                 System.out.println("Connected");
  30.             }
  31.         } catch (SQLException ex) {
  32.             ex.printStackTrace();
  33.         }
  34.         return conn;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement