Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.SQLException;
  4.  
  5. public class Sample {
  6.   private static final String USERNAME = "root";
  7.   private static final String PASSWORD = "alan";
  8.   private static final String CONN_STRING = "jdbc:mysql://localhost:3306/sample?useTimezone=true&serverTimezone=UTC";
  9.  
  10.   public static void main(String[] args) throws ClassNotFoundException{
  11.     Connection conn = null;
  12.     try {
  13.       Class.forName("com.mysql.cj.jdbc.Driver");
  14.       conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
  15.       System.out.println("Connected");
  16.     } catch (SQLException e) {
  17.       System.out.println("SQLException: " + e.getMessage());
  18.       System.out.println("SQLState: " + e.getSQLState());
  19.       System.out.println("VendorError: " + e.getErrorCode());
  20.     }
  21.   }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement