Advertisement
Guest User

Untitled

a guest
Nov 27th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. package com.MDB.test;
  2.  
  3. import java.sql.*;
  4.  
  5. /**
  6. * Created by res on 27.11.2016.
  7. */
  8.  
  9. public class DBconnect {
  10.  
  11. private final String URL = "jdbc:mysql://localhost:3306/test";
  12. private final String USER = "root";
  13. private final String PASSWORD = "root";
  14.  
  15. private Connection connection;
  16.  
  17. public DBconnect () {
  18.  
  19. try {
  20. connection = DriverManager.getConnection(URL, USER, PASSWORD);
  21. if (!connection.isClosed()) {System.out.println("Соединение с БД установелено!");
  22. }
  23. }
  24. catch (SQLException e){ e.printStackTrace();}
  25.  
  26.  
  27. }
  28. //устанавливаем getter, чтобы могли получать наш connection
  29. public Connection getConnection() {
  30. return connection;
  31. }
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement