Guest User

Untitled

a guest
Jan 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. public class Tutorial {
  2.    static String bd = "Tutorial";
  3.    static String login = "root";
  4.  
  5.  
  6.    static String password = "1234";
  7.    static String url = "jdbc:mysql://localhost/";
  8.    
  9.     public static void main(String[] args) throws InstantiationException, IllegalAccessException {
  10.       Connection conn = null;
  11.  
  12.       try {
  13.  
  14.          Class.forName("com.mysql.jdbc.Driver").newInstance();
  15.  
  16.          conn = DriverManager.getConnection(url,login,password);
  17.  
  18.          if (conn != null) {
  19.             System.out.println("Conexión a base de datos "+url+" ... Ok");
  20.             conn.close();
  21.          }
  22.       }
  23.       catch(SQLException ex) {
  24.          System.out.println("Hubo un problema al intentar conectarse con la base de datos "+url);
  25.       }
  26.       catch(ClassNotFoundException ex) {
  27.          System.out.println(ex);
  28.       }
  29.  
  30.     }
  31. }
Add Comment
Please, Sign In to add comment