Pom.xml Mysql-connector-java

0 views
Skip to first unread message

Eddie Listner

unread,
Jun 30, 2024, 10:23:04 AM6/30/24
to epunecmo

You just declared the dependency, but you did not use it. If this driver is already bundled as OSGI service, you should add it to your ui.apps/pom.xml and declare it to be embedded into the content-package. Just like [1] but for the mysql driver.

Hello, the error java.sql.SQLException: Cannot load JDBC driver class 'com.mysql.cj.jdbc.Driver' indicates an issue with declaring the dependencies in Maven. I followed the documentation at Use MySQL in a Development Environment - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS and applied it to a new 15.1.4 archetype project, it seems to work fine. I am attaching the pom.xml as well as the contenxt.xml and repository.xml. Tweak these as needed for your system.

The _bundle tables is where Jackrabbit, which is the repository that the CMS uses to store all data, persists the nodes and all their properties. default_bundle would be for the default workspace while version_bundle is for storing versioning information. If you take a look at the repository.xml you can see where these are configured.

And on another hand we are trying to migrate our MySQL database to a PostGres DB using the jackrabbit standalone server funtionality (GitHub - woonsanko/recipe-for-hippo-db-migration: Recipe for Hippo CMS Database Migration)
but when we execute the process is throwing a casting error

Hi David,
I am using CMS given docker only with below command " mvn clean install ; mvn -P docker.build, but have not called mysql profile. Can you please share your docker command?. Apart from this for H2 data base we had used REPO_PATH=$docker.brxm.project.path/target/storage, in case of mysql what would be REPO_PATH?

Thanks @David, finally I connected with one of my database(mydb) and not loosing my data after new builds or scale up/down. Now I am trying to connect with another database(X) since I am reading data from env specific config file so can change on the fly, if I do that and after scale down/up I get below error, now it is expecting some tables, mean to say that at run time not creating any tables.

MySQL is a fast, multi-user SQL database service. MySQL Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software. For more information, see the MySQL documentation page.

Advanced: Database has been tested and validated to deliver a minimum set of advanced capabilities around database inspection, support for long-running operations, as well as the Foundational level's basic functionality of change management and change tracking aligned with the database. The advanced database inspection capabilities include the ability to generate changelogs in at least one format and the support of at least two additional state-based commands (snapshots, diffs, etc). The Liquibase customer support team provides how-to/usage support around verified capabilities for commercial customers.

To use Liquibase with Maven, you must instead include the driver JAR(s) as a dependency in your pom.xml file. Using this information, Maven automatically downloads the driver JAR from Maven Central when you build your project.

I need to connect to an external mysql database from my JIRA plugin, for which I have included the mysql-connector-java dependency in my pom.xml.
After doing and atlas-clean and package, when I install the plugin, it says

The DataSource works as a factory for providing database connections. It is an alternative to the DriverManager facility. A datasource uses a URL along with username/password credentials to establish the database connection.

During application startup, the DataSourceAutoConfiguration checks for DataSource.class (or EmbeddedDatabaseType.class) on the classpath and a few other things before configuring a DataSource bean for us.

If not already defined, include spring-boot-starter-data-jpa to the project that transitively brings all necessary dependencies including JDBC drivers for various databases e.g. mysql-connector-java for connecting to MySQL database.

DataSource configuration is provided by configuration properties entries ( spring.datasource.* ) in application.properties file. The properties configuration decouples the configuration from the application code. This way, we can import the datasource configurations from even external configuration provider systems.

For a pooling datasource to be created, Spring Boot verifies that a valid Driver class is available. Note that if we set spring.datasource.driver-class-name property then the mentioned driver class must be found and loaded.

When we use this starter, Spring Boot will automatically configure a HikariCP connection pool based on sensible default settings. We can further customize the HikariCP configuration, if required, using the implementation-specific settings by changing their respective prefix (spring.datasource.hikari.*, spring.datasource.tomcat.*, and spring.datasource.dbcp2.*).

Spring boot tries to find and configure connection pooling, first HikariCP, second Tomcat pooling, and finally Commons DBCP2. HikariCP comes inbuilt with spring-boot-starter-jdbc or spring-boot-starter-data-jpa starters.

We can configure multiple datasources, and we must mark as one of them @Primary. The primary datasource is autowired by default, and other datasources need to be autowired along with @Qualifier annotation.

Java applications connect to and interact with relational databases through the Java Database Connectivity (JDBC) API. You can configure a data source and a JDBC driver so an application that is running on your Open Liberty server can connect with a relational database.

Applications communicate with relational databases to retrieve different kinds of information, such as flight schedules, product inventories, and customer purchase histories. The JDBC API provides an adapter layer between applications and relational databases by providing details about a database to an application in a standardized way. In Open Liberty, interactions with the JDBC API are configured by the Java Database Connectivity feature.

To connect with a relational database, you need a JDBC driver, which is typically provided by the database vendor. You can configure JDBC drivers to define data sources, from which you obtain connections to the database. To configure a JDBC data source in your Open Liberty server configuration, you must enable the Java Database Connectivity feature and specify a library that contains your JDBC driver. In the following server.xml file example, the library element specifies the location of the directory that contains a JDBC driver JAR file:

If you use Maven or Gradle build tools to build your application, you can configure a dependency to copy the JDBC driver files to the $server.config.dir/jdbc directory. The driver files must be copied after the server is created but before the application is deployed so that the database instance is available to the application at run time.

If you use Maven to build your application, you can download and deploy the JDBC driver by adding code that is similar to the following example to your pom.xml file. In this example, the driver files are copied to the jdbc directory that is in the $server.config.dir directory:

This example uses version 3.3.4 of the Liberty Maven plug-in. To use a different version, update the version value to specify the version that you want to use. For more information, see Copying dependencies with the Open Liberty Maven plug-in.

If you use Gradle to build your application, first add a copy task to your build.gradle file. Then, add a dependency for that task to the deploy task so that the copy task runs after the server is created but before the application is deployed:

In this build.gradle file example, a configurations instance that is called jdbcLib is declared with a dependency for the driver. The copyJDBC task specifies that the driver JAR files are copied into the jdbc folder in the server configuration directory. Finally, a deploy.dependsOn dependency specifies that the driver must be copied to the server before the application is deployed so it can be available at run time.

You can configure any JDBC driver with Open Liberty, which includes built-in configuration for many common vendor databases. The following example shows the basic pattern to configure a data source in your server.xml file:

Every JDBC driver provides a different collection of properties that you can configure on its dataSource implementation classes. If the JDBC driver data source has setter methods with a String or primitive parameter, you can configure these properties by specifying either a single properties or properties.JDBC_vendor_type subelement under the dataSource element. Use a properties.JDBC_vendor_type subelement if Liberty provides one for the JDBC driver that you are using. Otherwise, use a properties subelement. For more information about the vendor-specific properties.JDBC_vendor_type subelements that Liberty provides, see the dataSource element.

For an example of a vendor-specific properties subelement, consider the IBM Db2 JDBC driver, for which Open Liberty provides the properties.db2.jcc subelement. The following application code shows the currentLockTimeout property on the IBM Db2 JDBC driver data source classes:

After you configure a data source, you can quickly test the configuration to see whether your Open Liberty server can access your database. For more information, see Validating a connection to a database.

If you enable any Java EE or Jakarta EE features in Open Liberty, you can configure a default data source. To configure a default data source, set the ID of the dataSource element to DefaultDataSource, as shown in the following example:

The following examples show sample configurations for commonly used vendor databases. For applicable vendors, examples are provided for how to configure the database locally in a container for testing and development purposes:

d3342ee215
Reply all
Reply to author
Forward
0 new messages