Driver Available Parameters
In this chapter you will learn:
List of available parameters
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;
//j av a2 s . co m
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("Name:"+info[i].name);
System.out.println("Required:"+info[i].required);
System.out.println("Value:"+info[i].value);
System.out.println("Info:"+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("Choice:"+choices[c]);
}
}
}
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Driver and Connection