Guest User

Untitled

a guest
Apr 15th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1.             String host = "jdbc:mysql://localhost:3306/";
  2.             String username = "root ";
  3.             String password = "";
  4.             String database = "medorial";
  5.            
  6.             // attempt to connect
  7.             Connection conn = null;
  8.             String driver = "com.mysql.jdbc.Driver";
  9.             boolean hasConnected = false;
  10.            
  11.             try
  12.             {
  13.                 Class.forName(driver).newInstance();
  14.                 conn = DriverManager.getConnection(host+database,username,password);
  15.                 System.out.println("Connected to the database");
  16.                 //conn.close();
  17.                 //System.out.println("Disconnected from database");
  18.                 hasConnected = true;
  19.             }
  20.             catch (Exception e)
  21.             {
  22.                 System.out.println("\nMYSQL connection failed: \n");
  23.                 e.printStackTrace();
  24.                 System.out.println("Try again? \n");
  25.             }
Add Comment
Please, Sign In to add comment