Advertisement
Guest User

Untitled

a guest
Apr 30th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 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 daos;
  7. import java.sql.*;
  8. /**
  9. *
  10. * @author ASUS
  11. */
  12. public class Connect {
  13. private static Connection Con;
  14. private static final String URL="jdbc:mysql://localhost:3306/for_Opp";
  15. private static final String Drivername="com.mysql.jdbc.driver";
  16. private static final String Username="root";
  17. private static final String Password="";
  18.  
  19. public static Connection OpenCon(){
  20. if(Con==null){
  21. try{
  22. Class.forName(Drivername);
  23. try{
  24. Con=(com.mysql.jdbc.driver)
  25. DriverManager.getConnection(URL,Username,Password);
  26. }
  27. catch(SQLException sqle){
  28. System.out.println("Tidak terhubung ke database "+sqle);
  29. }
  30. }
  31. catch(ClassNotFoundException e){
  32. System.out.println("Driver not found "+e);
  33. }
  34. }
  35. return Con;
  36. }
  37. public static connection CloseCon(){
  38. if(kon != null){
  39. try{
  40. kon.close();
  41. }catch(SQLException e){
  42. System.out.println("Error "+e);
  43. }
  44. }
  45. return Con;
  46. }
  47. public static void main(String[]args){
  48. new Connect();
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement