Guest User

Untitled

a guest
Mar 28th, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. package Connect;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class ConnectBase {
  9. private static ConnectBase ourInstance = null;
  10.  
  11. public static ConnectBase getInstance() {
  12.  
  13. if (ourInstance == null) {
  14.  
  15. String polaczenieURL = "jdbc:mysql://127.0.0.1/quiz?user=root&password=root";
  16. Connection conn = null;
  17. try {
  18.  
  19. //Ustawiamy sterownik MySQL
  20. Class.forName("com.mysql.jdbc.Driver");
  21.  
  22. //Ustawiamy dane dotyczące podłączenia
  23. conn = DriverManager.getConnection(polaczenieURL);
  24.  
  25. //Uruchamiamy zapytanie do bazy danych
  26. Statement stat = conn.createStatement();
  27.  
  28.  
  29.  
  30.  
  31. } catch (Exception bi) {
  32.  
  33. System.out.println("Nie mogę poprawić danych " + bi.getMessage());
  34. }
  35. }
  36.  
  37.  
  38.  
  39.  
  40. return ourInstance;
  41. }
  42.  
  43. private ConnectBase() {
  44. }
  45. }
Add Comment
Please, Sign In to add comment