Java tutorial
import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; public class Main { public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); DatabaseMetaData meta = conn.getMetaData(); try { int majorVersion = meta.getDatabaseMajorVersion(); System.out.println("major Version: " + majorVersion); int minorVersion = meta.getDatabaseMinorVersion(); System.out.println("minorVersion" + minorVersion); } catch (Exception e) { System.out.println("minorVersion unsupported feature"); } String productName = meta.getDatabaseProductName(); String productVersion = meta.getDatabaseProductVersion(); System.out.println("productName" + productName); System.out.println("productVersion" + productVersion); conn.close(); } public static Connection getMySqlConnection() throws Exception { String driver = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost/databaseName"; String username = "root"; String password = "root"; Class.forName(driver); Connection conn = DriverManager.getConnection(url, username, password); return conn; } public static Connection getOracleConnection() throws Exception { String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:databaseName"; String username = "name"; String password = "password"; Class.forName(driver); Connection conn = DriverManager.getConnection(url, username, password); return conn; } }