import java.sql.*; /* Testing the JDBC MySQL driver installation. This program just opens a connection and then closes it and displays a message */ public class ConnectionTester { public static void main(String[] args) { // Connection parameters String host = "localhost"; // default value String port = "3306"; // default value String user = ""; // command line arg 0 String password = ""; // command line arg 1 String database = ""; // command line arg 2 if (args.length == 3) { user = args[0]; password = args[1]; database = args[2]; } else { System.out.println("args: user password database"); System.exit(0); } try { // Load the driver class dynamically. // This creates an instance of the class Class.forName("com.mysql.jdbc.Driver"); // Make a database connection and close it Connection conn = DriverManager.getConnection( "jdbc:mysql://" + host + ":" + port + "/" + database + "?user=" + user + "&password=" + password); conn.close(); } catch (ClassNotFoundException e) { System.out.println("Could not find the MySQL driver"); System.exit(0); } catch (SQLException e) { System.out.println(e.getMessage()); System.exit(0); } System.out.println("Connection to " + database + " was successful"); } }