How to determine the type of database to obtain? After searching on the Internet for a long time, I finally got something. As follows:
If you use spring's jdbcTemplate, you can get it like this:
DatabaseMetaData md = this.jdbcTemplate.getDataSource().getConnection().getMetaData(); System.out.println(md.getDatabaseProductName()); System.out.println(md.getDatabaseProductVersion());
If it is a dataSource configured by yourself, you can directly get the Connection, and then get the DatabaseMetaData, such as:
try { String url = "jdbc:odbc:yourdatabasename"; String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; String user = "guest"; String password = "guest"; Class.forName(driver); Connection connection = DriverManager.getConnection(url, user, password); DatabaseMetaData meta = connection.getMetaData(); System.out.println("We are using " + meta.getDatabaseProductName()); System.out.println("Version is " + meta.getDatabaseProductVersion() ); connection.close(); } catch (Exception e) { System.err.println(e); }