Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 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 com.koneksi;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.SQLException;
  10. import javax.swing.JOptionPane;
  11. /**
  12. *
  13. * @author Hp
  14. */
  15. public class koneksi {
  16. private static Connection koneksi;
  17. public static Connection getKoneksi()
  18. {
  19. if(koneksi== null)
  20. {
  21. try {
  22. String url="jdbc:mysql://localhost/web";
  23. String username= "root"; // default username
  24. String password= ""; // jika ada password bisa anda masukkan
  25.  
  26. DriverManager.registerDriver(new com.mysql.jdbc.Driver());
  27. koneksi =DriverManager.getConnection(url, username, password);
  28. } catch (Exception e) {
  29. System.out.println(e);
  30. }
  31. }
  32.  
  33. return koneksi;
  34. }
  35.  
  36. public void koneksiDatabase() {
  37. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement