Application Development with MariaDB Connector/J
Using projects with MariaDB Connector/J vary depending on the installation method you use.
Build with the JAR File
When developing your Java application without Maven, the process is more manual:
Add your application and the JAR for MariaDB Connector/J to the Java
$ export CLASSPATH="/path/to/application:/path/to/mariadb-java-client-2.7.4.jar"
Compile your application:
$ javac App.java
Execute the Java class:
$ java App
Build with a Java IDE
If using a Java IDE, create a Maven project and add the dependencies to
For additional information, see "Install MariaDB Connector/J via Maven".
Build with Maven
When using command-line Maven to manage your Java builds, running build downloads and installs the relevant JAR dependencies and compiles your project:
Build the package:
$ mvn package
Run the application:
$ java -jar target/app.jar
Connections are created, used, and managed using the following Java classes:
Represents a connection with a specific database.
Manages JDBC Drivers including establishing a connection to a database.
Statements are executed using the following Java classes:
Use a prepared SQL statement when the query needs to execute multiple times in succession or when it requires text from the user to specify the fields to protect against SQL injections.
Create an SQL statement when you need to execute a single self-contained query that does not require text from the user.