Guest User

Untitled

a guest
Mar 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 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 studentSystem;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.util.logging.Level;
  11. import java.util.logging.Logger;
  12.  
  13. /**
  14. *
  15. * @author Chingiz Mammadli
  16. */
  17. public class Database {
  18. public Connection conn = null;
  19.  
  20. public Database(){
  21. if(getConnection()){
  22. System.out.println("Connected");
  23. }else{
  24. System.out.println("Not connected");
  25. }
  26. }
  27.  
  28. private boolean getConnection(){
  29. String url = "jdbc:mysql://localhost:3306/java_web";
  30. String username = "root";
  31. String password = "";
  32.  
  33. try{
  34. Class.forName("com.mysql.jdbc.Driver");
  35. conn = DriverManager.getConnection(url,username,password);
  36. return true;
  37. }catch(Exception e){
  38. System.out.println(e.getMessage());
  39. Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, e);
  40. return false;
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment