Skip to content

Commit 8b3d825

Browse files
committed
Add info regarding the ServiceLoader provider configuration file
1 parent eaa04b7 commit 8b3d825

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,38 @@ public class OpctConfig extends SettingsCore<OpctConfig.OpctValues> {
213213
}
214214
```
215215

216+
### Registering JDBC Drivers
217+
218+
To provide maximum flexibility, JDBC interacts with database instances through a defined interface (**java.sql.Driver**). Implementations of this interface translate its methods into their vendor-specific protocol, in classes called **drivers**. For example, [OracleDriver](https://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/jdbc/OracleDriver.html) enables JDBC to interact with Oracle database products.
219+
220+
In JDBC connection URLs, the vendor and driver are specified as suffixes to the `jdbc` protocol. For the Oracle "thin" driver, this is `jdbc:oracle:thin`. This protocol/vendor/driver combination is handled by **OracleDriver**, and JDBC needs this class to be registered to handle this vendor-specific protocol.
221+
222+
To simplify the process of registering vendor-specific JDBC drivers, **DatabaseUtils** loads these for you through the Java **ServiceLoader** facility. Declare the driver(s) you need in a **ServiceLoader** provider configuration file at **_META-INF/services/java.sql.Driver_**:
223+
224+
```
225+
oracle.jdbc.OracleDriver
226+
```
227+
228+
This sample provider configuration file will cause **DatabaseUtils** to load the JDBC driver class for Oracle database products. The JAR that declares this class needs to be on the class path for this to work. For Maven projects, you just need to add the correct dependency:
229+
230+
```xml
231+
[pom.xml]
232+
<project ...>
233+
[...]
234+
235+
<dependencies>
236+
[...]
237+
<dependency>
238+
<groupId>com.oracle.jdbc</groupId>
239+
<artifactId>ojdbc6</artifactId>
240+
<version>11.2.0.4.0</version>
241+
</dependency>
242+
</dependencies>
243+
244+
[...]
245+
</project>
246+
```
247+
216248
## PathUtils
217249

218250
The **PathUtils** `getNextPath` method provides a method to acquire the next file path in sequence for the specified base name and extension in the indicated target folder. If the target folder already contains at least one file that matches the specified base name and extension, the algorithm used to select the next path will always return a path whose index is one more than the highest index that currently exists. (If a single file with no index is found, its implied index is 0.)

0 commit comments

Comments
 (0)