Mega Code Archive

 
Categories / Java Tutorial / Database
 

Get a List of all Available Parameters for Creating a JDBC Connection

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]);         }       }     }   } }