Get a List of all Available Parameters for Creating a JDBC Connection : Driver « Database « Java Tutorial






Driver.getPropertyInfo() returns a list of all available properties that can be supplied when using the driver to create a JDBC connection.

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;

public class Main {
  public static void main(String[] args) throws Exception {

    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:mem:data/tutorial";

    Driver driver = DriverManager.getDriver(url);

    DriverPropertyInfo[] info = driver.getPropertyInfo(url, null);
    for (int i = 0; i < info.length; i++) {
      System.out.println(info[i].name);
      // Is property value required?
      System.out.println(info[i].required);
      // Get current value
      System.out.println(info[i].value);
      // Get description of property
      System.out.println(info[i].description);

      // Get possible choices for property;
      // if null, value can be any string
      String[] choices = info[i].choices;
      if (choices != null) {
        for (int c = 0; c < choices.length; c++) {
          System.out.println(choices[c]);
        }
      }
    }

  }
}








20.2.Driver
20.2.1.A List of JDBC Drivers: connection string, driver name
20.2.2.DriverManager.getDrivers(): enumerate all the loaded JDBC drivers:
20.2.3.Setting the Login Timeout
20.2.4.Get a List of all Available Parameters for Creating a JDBC Connection
20.2.5.String java.sql.DriverPropertyInfo.name (Get name of property)
20.2.6.boolean java.sql.DriverPropertyInfo.required (Is property value required?)
20.2.7.String java.sql.DriverPropertyInfo.value (Get current value)
20.2.8.String java.sql.DriverPropertyInfo.description (Get description of property)
20.2.9.String[] java.sql.DriverPropertyInfo.choices (Get possible choices for property; if null, value can be any string)
20.2.10.DriverPropertyInfo[] java.sql.Driver.getPropertyInfo(String url, Properties info)
20.2.11.int java.sql.Driver.getMajorVersion()
20.2.12.int java.sql.Driver.getMinorVersion()
20.2.13.boolean java.sql.Driver.jdbcCompliant()
20.2.14.Getting Information about the Driver
20.2.15.Enable JDBC logging
20.2.16.Specify a CharSet when connecting to a DBMS
20.2.17.Listing All Available Parameters for Creating a JDBC Connection