What Connection Properties Should You Supply to a Database Driver in Order to Connect to a Database? JDBC

In general, when creating a database connection object (java.sql.Connection), most JDBC drivers should accept three connection properties:

  • user (database user)
  • password (database user’s password)
  • hostname (hostname where database resides)

Also, a JDBC driver may accept an arbitrary number of proprietary connection properties. For example, MySQL’s JDBC driver (for details on MySQL’s connection properties. can accept over a dozen additional connection properties, such as connectTimeout and use Compression. JDBC drivers can be interrogated for their supported connection properties using the DriverPropertyInfo metadata class. For specific database connection properties, you should consult the vendor’s JDBC driver documentation (this documentation should specify all properties and their role in creating the JDBC database connection).

The Solution

This solution identifies which connection properties are required and which ones are optional:

Running the Solution for a MySQL Database

Because the output was long, I have edited it to fit the page:

Running the Solution for an ODBC Database

The JDBC-ODBC bridge driver does not properly return an array of DriverPropertyInfo objects, but instead throws either a NullPointer Exception or java.sql.SQLException:

Running the Solution for an Oracle Database

Oracle’s JDBC driver does not implement Driver.getPropertyInfo() properly. It just returns an empty array. Here is a section of code from Oracle’s JDBC driver:



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics