edwardbeckett
1/14/2015 - 6:29 AM

DBConnection

import java.sql.*;

public class DBConnection {

	public DBConnection(String username, String password, String db) {
		Connection conn;
		try {
			String url = "jdbc:mysql://localhost:3306/" + db;
			Class.forName( "com.mysql.jdbc.Driver" ).newInstance();
			conn = DriverManager.getConnection( url, username, password );
			System.out.println( "Connection Successful ... " );
			conn.close();
		} catch( ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException e ) {
			System.out.println( "There was an error...  ");
			e.printStackTrace();
		}
	}

	public static void main( String[] args ) {

		DBConnection connection = new DBConnection( "root", "root", "example3" );
	}
}