The work often tells a database server about JDBC connection information, not the database version, so that development is not afraid to use the latest features of the database. I wrote a small program to detect the remote database server type:
Import java.sql.Connection; Import Java.sql.DatabaseMetaData; Import Java.sql.DriverManager; Import java.sql.SQLException; public class Dbversiondetector {public static void main (string[] args) throws Instantiationexception, Illegalaccessexcep tion, classnotfoundexception, SQLException {//class.forname ("Oracle.jdbc.driver.OracleDriver"). newinstance (); Class.forName ("Com.ibm.db2.jcc.DB2Driver"). newinstance (); Connection conn = Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:test", "oral", "oral"); Connection conn = drivermanager.getconnection ("Jdbc:db2://localhost:50000/sample", "Db2admin", "db2admin"); DatabaseMetaData meta = conn.getmetadata (); System.out.println ("url:/t" + Meta.geturl ()); System.out.println ("username:/t" + meta.getusername ()); System.out.println ("databaseproductname:/t" + meta.getdatabaseproductname ()); System.out.println ("databasemajorversion:/t" + meta.getdatabasemajorversion ()); System.out.println ("databaseminorversion:/t" + Meta.getdatabaseminorvErsion ()); System.out.println ("databaseproductversion:/t" + meta.getdatabaseproductversion ()); System.out.println ("drivername:/t" + meta.getdrivername ()); System.out.println ("drivermajorversion:/t" + meta.getdrivermajorversion ()); System.out.println ("driverminorversion:/t" + meta.getdriverminorversion ()); System.out.println ("driverversion:/t" + meta.getdriverversion ()); System.out.println ("jdbcmajorversion:/t" + meta.getjdbcmajorversion ()); System.out.println ("jdbcminorversion:/t" + meta.getjdbcminorversion ()); Conn.close (); } }
The results of the operation are as follows (example):
Url:jdbc:db2://localhost:50000/sample username:db2admin databaseproductname:db2/nt Databasemajorversion:9 Databaseminorversion:7 databaseproductversion:sql09070 DRIVERNAME:IBM DB2 JDBC Universal Driver Architecture DriverMaj Orversion:3 driverminorversion:57 driverversion:3.57.82 Jdbcmajorversion:3 jdbcminorversion:0
You can see from here that this is a DB2 v9.7 for Windows Server that supports JDBC3.0.