Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DB_connect;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- * Created by Konstantin on 15.03.2018.
- */
- public class ContectToDB {
- /* private static final String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=WINTOUR";
- private static final String user = "KOS";
- private static final String password = "1";
- // JDBC variables for opening and managing connection
- private static Connection con;
- private static Statement stmt;
- */
- public static void main(String[] args) {
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- System.out.println("Driver loading success!");
- String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=ElectronicVt";
- String user = "";
- String password = "";
- try{
- Connection con = DriverManager.getConnection(url,user,password); // Создание соединения с БД.
- System.out.println("Connected!");
- con.close(); //Закрытие подключение к БД.
- System.out.println("Disconnected!");
- }catch (SQLException e) {
- e.printStackTrace();
- System.out.println("Something wrong with connection!");
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment