Guest User

Untitled

a guest
Mar 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package DB_connect;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. /**
  8. * Created by Konstantin on 15.03.2018.
  9. */
  10. public class ContectToDB {
  11.  
  12. /* private static final String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=WINTOUR";
  13. private static final String user = "KOS";
  14. private static final String password = "1";
  15.  
  16. // JDBC variables for opening and managing connection
  17. private static Connection con;
  18. private static Statement stmt;
  19. */
  20.  
  21. public static void main(String[] args) {
  22. try {
  23. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  24. System.out.println("Driver loading success!");
  25.  
  26. String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=ElectronicVt";
  27. String user = "";
  28. String password = "";
  29.  
  30. try{
  31. Connection con = DriverManager.getConnection(url,user,password); // Создание соединения с БД.
  32. System.out.println("Connected!");
  33.  
  34. con.close(); //Закрытие подключение к БД.
  35. System.out.println("Disconnected!");
  36. }catch (SQLException e) {
  37. e.printStackTrace();
  38. System.out.println("Something wrong with connection!");
  39. }
  40.  
  41. } catch (ClassNotFoundException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment