Obtener información de un driver dado des de una aplicación

2902 vistas

Tendremos que usar los métodos dados por la interfaz Driver:



java
  1. Driver driver =...;
  2. String url = "url JDBC";
  3. int majorVersion = driver.getMajorVersion();
  4. int minorVersion = driver.getMinorVersion();
  5. DriverPropertyInfo[] props = driver.getPropertyInfo(url,null);
  6. System.out.println("Driver class = "+driver.getClass()+ "
  7.     v"+majorVersion+"."+minorVersion);
  8. for(int i=0 ;i<props.length;i++){
  9.   DriverPropertyInfo prop = props[i];
  10.   System.out.println("Prop name = "+prop.name);
  11.   System.out.println("Prop description = "+prop.description);
  12.   System.out.println("Prop value = "+prop.value);
  13.   if(prop.choices!=null){
  14.     for(int j=0;j<prop.choices.length;j++){
  15.       System.out.println("prop choice "+j+" = "+prop.choices[j]);
  16.     }
  17.   }
  18. }



Veamos la salida para MySQL Connector/J:



java
  1. Driver class com.mysql.jdbc.Driver v3.0
  2. Prop name = HOST
  3. Prop description = Hostname of MySQL Server
  4. Prop value = localhost
  5. Prop name = PORT
  6. Prop description = Port number of MySQL Server
  7. Prop value = 3306
  8. Prop name = DBNAME
  9. Prop description = Database name
  10. Prop value = test
  11. Prop name = user
  12. Prop description = Username to authenticate as
  13. Prop value = null
  14. Prop name = password
  15. Prop description = Password to use for authentication
  16. Prop value = null
  17. Prop name = autoReconnect
  18. Prop description = Should the driver try to re-establish bad connections?
  19. Prop value = false
  20. prop choice 0 = true
  21. prop choice 1 = false
  22. Prop name = maxReconnects
  23. Prop description = Maximum number of reconnects to attempt if autoReconnect is true
  24. Prop value = 3
  25. Prop name = initialTimeout
  26. Prop description = Initial timeout (seconds) to wait between failed connections
  27. Prop value = 2
  28. //+ 90 líneas