Confluence is currently tested with the 8.0.22 driver. Database setup for MySQL: Oracle. JDBC driver downloads. Due to licensing constraints, Oracle drivers are not bundled with Confluence. For Oracle 12c R2 use the 12.2.0.x driver (ojdbc8.jar) For Oracle 19c you can use either ojdbc8.jar.
DriverManager
Interface When you are using JDBC outside of an application server, the DriverManager
class manages the establishment of connections.
JDBC Type 4 driver for MySQL License: GPL 2.0: Categories: MySQL Drivers: Tags: mysql database connector driver: Used By: 5,271 artifacts: Central (84) Jahia (1. Tomcat MySQL connection - Using JDBC to connect Tomcat to MySQL Stumped by Tomcat JDBC connections? Can't get your head around MySQL drivers, connection pools, and JNDI resources? This article will guide you step-by-step through connecting your MySQL.
Specify to the DriverManager
which JDBC drivers to try to make Connections with. The easiest way to do this is to use Class.forName()
on the class that implements the java.sql.Driver
interface. With MySQL Connector/J, the name of this class is com.mysql.jdbc.Driver
. With this method, you could use an external configuration file to supply the driver class name and driver parameters to use when connecting to a database.
The following section of Java code shows how you might register MySQL Connector/J from the main()
method of your application. If testing this code, first read the installation section at Chapter 3, Connector/J Installation, to make sure you have connector installed correctly and the CLASSPATH
set up. Also, ensure that MySQL is configured to accept external TCP/IP connections.
After the driver has been registered with the DriverManager
, you can obtain a Connection
instance that is connected to a particular database by calling DriverManager.getConnection()
:
Example 6.1 Connector/J: Obtaining a connection from the DriverManager
If you have not already done so, please review the portion of Section 6.1, “Connecting to MySQL Using the JDBC DriverManager
Interface” above before working with the example below.
This example shows how you can obtain a Connection
instance from the DriverManager
. There are a few different signatures for the getConnection()
method. Consult the API documentation that comes with your JDK for more specific information on how to use them.
Once a Connection
is established, it can be used to create Statement
and PreparedStatement
objects, as well as retrieve metadata about the database. This is explained in the following sections.
It’s very strange if you are still using JDBC in your project for database access because there are lot’s of powerful alternatives like hibernate and iBatis. But it is important to learn basics and it requires learning JDBC first.
In this post, I am giving an example of making a connection with database using MySQL Driver. Read more about types of JDBC drivers.
Handling a connection requires following steps:
1) Load the driver
2) Open database connection
3) Close database connection
Let’s follow above steps in code:
The easiest way to do this is to use Class.forName() on the class that implements the java.sql.Driver interface. With MySQL Connector/J, the name of this class is com.mysql.jdbc.Driver. With this method, you could use an external configuration file to supply the driver class name and driver parameters to use when connecting to a database.
After the driver has been registered with the DriverManager, you can obtain a Connection instance that is connected to a particular database by calling DriverManager.getConnection():
Once a Connection is established, it can be used to create Statement and PreparedStatement objects, as well as retrieve metadata about the database.
This step is as much important as opening a connection. Any connection left open is waste of resource and lead to various exceptions.
Let’s see the whole thing working in an example below:
That’s all for this topic. Drop a comment if something needs more explanation.
Happy Learning !!