The java.sql.Driver.getPropertyInfo() method returns an array of DriverPropertyInfo objects (DriverPropertyInfo). JDBC’s Driver.getPropertyInfo() method allows a GUI tool to determine the database connection properties for which it should prompt a user in order to get enough information to connect to a database. Depending on the values the user has supplied so far, additional values might become necessary. It might be necessary to iterate through several calls to getPropertyInfo(). If no more properties are necessary (i.e., all required parameters are specified), the call returns an array of zero length. In general, Driver.getPropertyInfo() offers java.sql.Connection choices to the user.
How It Works
For most database systems, the properties returned in the DriverPropertyInfo object are connection URL attributes, including a list of booted databases in a system (the databaseName attribute). When a nonzero-length array (DriverPropertyInfo) is returned by the Driver. getPropertyInfo() method, each element is a DriverPropertyInfo object representing a connection URL attribute that has not already been specified.
The signature of the Driver.getPropertyInfo() method is/**
I’ll describe the Driver.getPropertyInfo() method next. This method gets information about the possible properties for this driver. The getPropertyInfo() method is intended to allow a generic GUI tool to discover what properties it should prompt the user for in order to get enough information to connect to a database. Note that depending on the values the user has supplied so far, additional values may be required, so it may be necessary to iterate through several calls to the getPropertyInfo() method. According to JDBC API Tutorial and Reference, Third Edition (Addison Wesley Publishing, August 1997):
The second argument should be null the first (and generally only) time this method is called. The second argument is included so that it is possible for an application to process input and present the human user with a list of properties from which to choose. Depending on the values the human has supplied so far, it is conceivable that additional values may be needed. In such cases, and assuming that the application has been written to handle the results of multiple calls to getPropertyInfo(), it may be necessary to iterate through several calls to getPropertyInfo(). If the application uses the information it gets to fill in values for a java.util.Properties object, then that object can be supplied to getPropertyInfo() in subsequent calls to the method. The properties returned by this method will often correspond to the properties that are set on a javax.sql.DataSource object for this driver.
Here is some example code for a MySQL/Oracle database. This solution displays Driver property information as an XML serialized String object. In this solution, I check for drivers from Oracle, MySQL, and JDBC-ODBC. You may alter the code and add additional drivers. To do this, modify the loadDriver() method.import java.sql.Driver;
Running the Solution for a MySQL Database
The following output is formatted to fit the page:$ javac TestDriverPropertyInfo.java
Running the Solution for an Oracle Database$ java TestDriverPropertyInfo oracle "jdbc:oracle:thin:@localhost:1521:caspian"
As you can see from the preceding output, the Oracle driver does not properly return an array of DriverPropertyInfo objects, but instead returns an empty array.
Running the Solution for a JDBC-ODBC Configured Database$ java TestDriverPropertyInfo "jdbc-odbc" "jdbc:odbc:northwind"
As the preceding output shows, the JDBC-ODBC bridge driver does not properly return an array of DriverPropertyInfo objects, but instead throws a java.sql.SQLException. The MySQL database driver works better in this respect.
JDBC Related Interview Questions
|Core Java Interview Questions||JSP Interview Questions|
|Java Servlets Interview Questions||EJB(Enterprise JavaBeans) Interview Questions|
|JSTL(JSP Standard Tag Library) Interview Questions||JNDI (Java Naming and Directory Interface) Interview Questions|
|Java Bean Utils Interview Questions||AWT (Abstract Window Toolkit) Interview Questions|
What Is Jdbc Programming?
Database Metadata, Part 1
Database Metadata, Part 2
Exploring Driver Property Information
Rowset Metadata A
Web Access To Metadata,part 1
Web Access To Metadata, Part 2
Rdf And Jdbc Metadata
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.