Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String host = "jdbc:mysql://localhost:3306/";
- String username = "root ";
- String password = "";
- String database = "medorial";
- // attempt to connect
- Connection conn = null;
- String driver = "com.mysql.jdbc.Driver";
- boolean hasConnected = false;
- try
- {
- Class.forName(driver).newInstance();
- conn = DriverManager.getConnection(host+database,username,password);
- System.out.println("Connected to the database");
- //conn.close();
- //System.out.println("Disconnected from database");
- hasConnected = true;
- }
- catch (Exception e)
- {
- System.out.println("\nMYSQL connection failed: \n");
- e.printStackTrace();
- System.out.println("Try again? \n");
- }
Add Comment
Please, Sign In to add comment