Advertisement
Guest User

Untitled

a guest
May 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 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.  
  18.     public static Connection connect(){
  19.         try{
  20.             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  21.             //System.out.println("Driver loaded");
  22.             // Connect to a database
  23.             connection = DriverManager.getConnection
  24.                     ("jdbc:sqlserver://s16988308.onlinehome-server.com:1433;databaseName=CUNY_DB;integratedSecurity=false;" , "cst3613", "e369");
  25.             //System.out.println("Database connected");
  26.             return connection;
  27.         }
  28.         catch (ClassNotFoundException | SQLException ex) {
  29.             ex.printStackTrace();
  30.         }
  31.         return connection;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement