Get JDBC driver information
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
public class Main{
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost/yourDatabase";
private static final String USERNAME = "root";
private static final String PASSWORD = "";
public static void main(String[] args) throws Exception {
Class.forName(DRIVER);
Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
DatabaseMetaData metadata = connection.getMetaData();
String driverName = metadata.getDriverName();
String driverVersion = metadata.getDriverVersion();
int majorVersion = metadata.getDriverMajorVersion();
int minorVersion = metadata.getDriverMinorVersion();
System.out.println("driverName = " + driverName);
System.out.println("driverVersion = " + driverVersion);
System.out.println("majorVersion = " + majorVersion);
System.out.println("minorVersion = " + minorVersion);
connection.close();
}
}
Related examples in the same category