Advertisement
Guest User

Untitled

a guest
May 3rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.*;
  2.  
  3. public class CheckDatabaseConnection {
  4.     private static final String DATABASE = "silvestri";
  5.     private static final String USERNAME = "readonly";
  6.     private static final String PASSWORD = "readonly";
  7.  
  8.  
  9.     static String driver = "com.mysql.jdbc.Driver";
  10.     static String url = "jdbc:mysql://cs.stcc.edu/" + DATABASE +
  11.                         "?user=" + USERNAME + "&password=" + PASSWORD;
  12.        
  13.         public static void main(String[] args) {
  14.             try {
  15.                 Class.forName(driver).newInstance();
  16.                 System.out.println("Loaded driver");
  17.                 try{
  18.                 Connection conn = Drivermanager.getConnection(url,);
  19.                 Connection conn = DriverManager.getConnection(url);}
  20.  
  21.                 System.out.println("Connected to database");
  22.  
  23.                
  24.                 System.out.println("Closed connection");   
  25.             }
  26.             catch (Exception e) {
  27.                 System.err.println(e.getMessage());
  28.             }
  29.         }
  30. }. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement