Apache Maven is a ubiquitous tool for Java development since it is very useful for managing dependencies on third party libraries in a transparent and maintainable way. From an application’s perspective is Mimer SQL JDBC driver such a third party library and it is available on Maven Central and can thus easily be included in a project’s POM.

Here is a very basic Java application that connects to a database on localhost called “mimerdb”. Save the source file as src/com/mimer/mvnMimerJDBC.java and the POM as pom.xml or download the source, then build and run the project:

mvn package
java -jar target/mvnMimerJDBC-1.0.jar

This is the java source for the example:

package com.mimer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class mvnMimerJDBC {
    static String dbHost = "localhost";
    static String dbName = "mimerdb";
    static String dbUser = "SYSADM";
    static String dbPass = "SYSADM";
    static Connection connection = null;

    /**
     * A very basic connection routine
     *
     * @return true if the connection was successful, false otherwise
     */
    private static boolean connectToMimer() {
        try {
            Class.forName("com.mimer.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Failed to load JDBC driver");
            e.printStackTrace();
            return false;
        }

        try {
            String s = "jdbc:mimer://" + dbHost + "/" + dbName;
            connection = DriverManager.getConnection(s, dbUser, dbPass);
        } catch (SQLException e) {
            System.out.println("Failed to connect to database");
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * To display some data from the database we use the system table "MANYROWS". It contains 366 records
     * of integers, 1 to 366, stored in one column named "C" and is perfect for this type of test run
     */
    private static void getDataFromMimer() {
        PreparedStatement preparedStatement;

        try {
            String queryStatement = "SELECT C FROM SYSTEM.MANYROWS";
            preparedStatement = connection.prepareStatement(queryStatement);
            ResultSet rs = preparedStatement.executeQuery();
            while (rs.next()) {
                int c = rs.getInt("C");
                System.out.format("%s\n", c);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        if (connectToMimer())
            getDataFromMimer();
    }
}

A corresponding POM file can look like this:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mimer</groupId>
    <artifactId>mvnMimerJDBC</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>mvnMimerJDBC</name>
    <url>https://developer.mimer.com</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.mimer.jdbc</groupId>
            <artifactId>mimjdbc</artifactId>
            <version>3.42.1-1</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>com.mimer.jdbc:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.MF</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <transformers>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.mimer.mvnMimerJDBC</mainClass>
                        </transformer>
                    </transformers>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>