Advertisement
Guest User

Untitled

a guest
May 16th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. import java.sql.*;
  2. public class dbConnect {
  3.     public static Connection connection=null;
  4.     dbConnect(){
  5.          try{
  6.                 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  7.                 //System.out.println("Driver loaded");
  8.                 // Connect to a database
  9.                 connection = DriverManager.getConnection
  10.                         ("jdbc:sqlserver://s16988308.onlinehome-server.com:1433;databaseName=CUNY_DB;integratedSecurity=false;" , "cst3613", "e369");
  11.                 //System.out.println("Database connected");
  12.             }
  13.             catch (ClassNotFoundException | SQLException ex) {
  14.                 ex.printStackTrace();
  15.             }
  16.     }
  17.     public void endConnect(){
  18.         try{
  19.             connection.close();
  20.             System.out.println("Database closed");
  21.         }
  22.         catch (SQLException ex) {
  23.             ex.printStackTrace();
  24.         }
  25.     }
  26.     public static Connection connect(){
  27.         try{
  28.             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  29.             //System.out.println("Driver loaded");
  30.             // Connect to a database
  31.             connection = DriverManager.getConnection
  32.                     ("jdbc:sqlserver://s16988308.onlinehome-server.com:1433;databaseName=CUNY_DB;integratedSecurity=false;" , "cst3613", "e369");
  33.             //System.out.println("Database connected");
  34.         }
  35.         catch (ClassNotFoundException | SQLException ex) {
  36.             ex.printStackTrace();
  37.         }
  38.         return connection;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement