import java.sql.*; public class JdbcExample1 { public static void main(String args[]) { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql:///test", "root", "rootpass"); if(!con.isClosed()) System.out.println("Successfully connected to MySQL server..."); System.out.println("|"+con.getMetaData().getDatabaseProductName()+"|"); System.out.println(" |"+con.getMetaData().getDatabaseProductVersion()+"|"); System.out.println("|"+con.getMetaData().getDriverName()+"|"); System.out.println(" |"+con.getMetaData().getDriverVersion()+"|"); } catch(Exception e) { System.err.println("Exception: " + e.getMessage()); } finally { try { if(con != null) con.close(); } catch(SQLException e) {} } } }