Skip to content

Commit 7fc2448

Browse files
committed
Update readme files
1 parent e84654a commit 7fc2448

File tree

20 files changed

+213
-242
lines changed

20 files changed

+213
-242
lines changed

README.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,49 @@
44

55
This repository contains examples on how to connect to [MariaDB](https://mariadb.com) databases using a combination of different Java libraries and frameworks.
66

7+
## Before you run the examples
8+
9+
1. Make sure you have a MariaDB Server ([Enterprise](https://mariadb.com/products/enterprise/) or [Community](https://mariadb.com/products/community-server/)) running. If you don't have a MariaDB server running, you can easily run one using [Docker](https://hub.docker.com/u/mariadb):
10+
11+
```Shell
12+
docker run --name mariadb --detach --publish 3306:3306 --env MARIADB_ROOT_PASSWORD='RootPassword123!' mariadb
13+
```
14+
15+
Alternatively, you can [Download](https://mariadb.com/downloads/) and install the server directly on your OS.
16+
17+
2. Connect to the database using [MariaDB Shell](https://mariadb.com/downloads/tools/shell/):
18+
19+
```shell
20+
mariadb-shell --dsn mariadb://root:'RootPassword123!'@127.0.0.1
21+
```
22+
23+
Alternatively, you can use any database client compatible with MariaDB.
24+
25+
3. Prepare the database schema and user as follows:
26+
27+
```sql
28+
CREATE DATABASE demo;
29+
CREATE USER 'user'@'%' IDENTIFIED BY 'Password123!';
30+
GRANT SELECT, INSERT, UPDATE, DELETE, DROP ON demo.* TO 'user'@'%';
31+
32+
CREATE TABLE demo.programming_language(
33+
pl_id INT PRIMARY KEY AUTO_INCREMENT,
34+
pl_name VARCHAR(50) NOT NULL UNIQUE,
35+
pl_rating INT
36+
);
37+
```
38+
739
## JDBC & JPA
840

941
- [JDBC (Java Database Connectivity)](jdbc/): The foundational technology used for persistence in Java.
10-
- [JPA/Hibernate](jpa-hibernate): The de-facto standard for consuming databases from Java apps.
42+
- [JPA/Hibernate](jpa-hibernate/): The de-facto standard for consuming databases from Java apps.
1143

1244
## Spring Boot
1345

1446
- [Spring Boot Data JPA](spring-boot-jpa/): Spring-based programming model for data access on top of JPA.
1547
- [R2DBC ➚](https://github.com/mariadb-developers/reactive-programming-java-examples): Reactive database connectivity.
1648
- [jOOQ](spring-boot-jooq/): Type-safe SQL queries in Java.
17-
- [MyBatis](spring-boot-mybatis): Map SQL results to Java methods in a simple way.
49+
- [MyBatis](spring-boot-mybatis/): Map SQL results to Java methods in a simple way.
1850

1951
## Jakarta EE (Java EE)
2052

jakarta-ee/README.md

+4-36
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,10 @@ List<ProgrammingLanguage> programmingLanguages = query.getResultList();
7474
- [MariaDB Connector/J](https://mariadb.com/downloads/connectors/connectors-data-access/java8-connector) 3.2.0 or later
7575
- An SQL client tool like [MariaDB Shell](https://mariadb.com/downloads/tools/), DBeaver, or an [SQL integration](https://www.youtube.com/watch?v=rJYUTxD-2-M) for your IDE
7676
- MariaDB server ([Enterprise](https://mariadb.com/products/enterprise/) or [Community](https://mariadb.com/products/community-server/))
77-
## Preparing the database
78-
79-
If you don't have a MariaDB server running, you can easily run using [Docker](https://hub.docker.com/u/mariadb):
80-
81-
```shell
82-
docker run --name mariadb -d -p 3306:3306 -e MARIADB_ROOT_PASSWORD='RootPassword123!' mariadb
83-
```
84-
85-
Alternatively, you can [Download](https://mariadb.com/downloads/) and install the server directly on your OS.
8677

87-
Connect to the database:
88-
89-
```shell
90-
mariadb-shell --dsn mariadb://root:'RootPassword123!'@127.0.0.1
91-
```
92-
93-
Alternatively, you can use any database client compatible with MariaDB.
94-
95-
Execute the following SQL statements to create a user for the JakartaEE application, a database (or schema) and a table:
96-
97-
```sql
98-
CREATE DATABASE demo;
99-
CREATE USER 'user'@'%' IDENTIFIED BY 'Password123!';
100-
GRANT SELECT, INSERT, UPDATE, DELETE, DROP ON demo.* TO 'user'@'%';
78+
## Preparing the database
10179

102-
USE demo;
103-
CREATE TABLE programming_language(
104-
pl_id INT PRIMARY KEY AUTO_INCREMENT,
105-
pl_name VARCHAR(50) NOT NULL UNIQUE,
106-
pl_rating INT
107-
);
108-
```
80+
See the instructions [here](../README.md).
10981

11082
## Configuring Glassfish
11183

@@ -138,10 +110,6 @@ In the JDBC Connection Pool list, click on **MariaDB**, select the **Additional
138110
* **user**: `user`
139111
* **password**: `Password123!`
140112

141-
> If you are using [MariaDB SkySQL](https://mariadb.com/products/skysql/), enable SSL and specify the path to the CA chain file that you can download from the [SkySQL Portal](https://cloud.mariadb.com):
142-
>
143-
> `jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:3306/demo?sslMode=verify-ca&serverSslCert=/path/to/your/skysql_chain.pem`
144-
145113
Go to **Resources > JDBC > JDBC Resources**. Click **New** and fill in the following details:
146114

147115
* **JNDI Name**: `mariadb-database`
@@ -163,9 +131,9 @@ To deploy the WAR file to GlassFish using the Administration Console, go to **Ap
163131

164132
## Check the output
165133

166-
Go to **Monitoring Data > server** and click either the **View Log Files** or **View Raw Log** button. You should be able to see log messages confirming that data was deleted, created, and read. You can also connect to the database and see the data in the `programming_language` table.
134+
Go to **Monitoring Data > server** and click either the **View Log Files** or **View Raw Log** button. You should be able to see log messages confirming that data was deleted, created, and read.
167135

168-
Connect to the database:
136+
You can also connect to the database and see the data in the `programming_language` table:
169137

170138
```shell
171139
mariadb-shell --dsn mariadb://user:'Password123!'@127.0.0.1

jdbc/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pool included with the MariaDB JDBC driver:
2222
See the **README.md** files in each subdirectory to learn how to run the
2323
examples.
2424

25+
See [this](../README.md) to set up the database.
26+
2527
## Support and Contribution
2628

2729
Please feel free to submit PR's, issues or requests to this project

jdbc/mariadb-pool/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ Change `Service` constructor to use a `MariaDbPoolDataSource` and run the app ag
1010

1111
## Requirements
1212

13-
- Java 17 or later. Previous versions should work (update the version
13+
- Java 21 or later. Previous versions should work (update the version
1414
in the **pom.xml** file).
1515
- [Apache Maven](https://maven.apache.org).
16-
- MariaDB server. If you don't want to install
17-
anything extra, try creating a free [SkySQL account](https://cloud.mariadb.com).
16+
- MariaDB server.
1817
- An SQL client tool like `mariadb`, DBeaver, or an SQL integration for
1918
your IDE.
2019

jdbc/mariadb-pool/src/main/java/com/example/Service.java

-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ private Service() throws SQLException {
4545
dataSource.setUser("user");
4646
dataSource.setPassword("Password123!");
4747
this.dataSource = dataSource;
48-
/*
49-
* If you are using MariaDB SkySQL (https://mariadb.com/products/skysql),
50-
* enable SSL and specify the path to the CA chain file that you can download
51-
* from the SkySQL Portal (https://cloud.mariadb.com):
52-
* jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/demo?sslMode=verify-ca&
53-
* serverSslCert=/path/to/your/skysql_chain.pem
54-
*/
5548
}
5649

5750
public static synchronized Service getInstance() throws SQLException {

jdbc/part1/README.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ the latest version):
1717
</dependency>
1818
```
1919

20-
Open the connection (alternatively use a try-catch block to close the connection automatically):
20+
Open the connection (alternatively use `try` with resources to close the connection automatically):
2121

2222
```java
2323
Connection connection = DriverManager.getConnection(
@@ -26,39 +26,30 @@ Connection connection = DriverManager.getConnection(
2626
);
2727
```
2828

29-
> If you are using [MariaDB SkySQL](https://mariadb.com/products/skysql/), enable SSL and specify the path to the CA chain file that you can download from the [SkySQL Portal](https://cloud.mariadb.com):
30-
>
31-
> `jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/database_name?sslMode=verify-ca&serverSslCert=/path/to/your/skysql_chain.pem`
32-
33-
Close the connection (if not using a try-catch block):
29+
Close the connection (if not using a `try` with resources block):
3430

3531
```java
3632
connection.close();
3733
```
3834

3935
## Requirements
4036

41-
- Java 17 or later. Previous versions should work (update the version
37+
- Java 21 or later. Previous versions should work (update the version
4238
in the **pom.xml** file).
4339
- [Apache Maven](https://maven.apache.org).
44-
- MariaDB server. If you don't want to install
45-
anything extra, try creating a free [SkySQL account](https://cloud.mariadb.com).
40+
- MariaDB server.
4641
- An SQL client tool like `mariadb`, DBeaver, or an SQL integration for
4742
your IDE.
4843

49-
## Running the app
44+
## Preparing the database
5045

51-
Prepare the database:
46+
See the instructions [here](../../README.md).
5247

53-
```sql
54-
CREATE DATABASE demo;
55-
CREATE USER 'user'@'%';
56-
GRANT ALL ON demo.* TO 'user'@'%' IDENTIFIED BY 'Password123!';
57-
```
48+
## Running the app
5849

5950
Run the following from the command line:
6051

61-
```
52+
```Shell
6253
git clone [email protected]:mariadb-developers/java-quickstart.git
6354
cd java-quickstart/jdbc/part1/
6455
mvn package

jdbc/part1/src/main/java/com/example/Application.java

-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ private static void initDatabaseConnection() throws SQLException {
3131
"jdbc:mariadb://127.0.0.1:3306/demo",
3232
"user", "Password123!");
3333
System.out.println("Connection valid: " + connection.isValid(5));
34-
/*
35-
If you are using MariaDB SkySQL (https://mariadb.com/products/skysql),
36-
enable SSL and specify the path to the CA chain file that you can download
37-
from the SkySQL Portal (https://cloud.mariadb.com):
38-
jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/demo?sslMode=verify-ca&serverSslCert=/path/to/your/skysql_chain.pem
39-
*/
4034
}
4135

4236
private static void closeDatabaseConnection() throws SQLException {

jdbc/part2/README.md

+22-18
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,44 @@ try (PreparedStatement statement = connection.prepareStatement("""
3636

3737
## Requirements
3838

39-
- Java 17 or later. Previous versions should work (update the version
39+
- Java 21 or later. Previous versions should work (update the version
4040
in the **pom.xml** file).
4141
- [Apache Maven](https://maven.apache.org).
42-
- MariaDB server. If you don't want to install
43-
anything extra, try creating a free [SkySQL account](https://cloud.mariadb.com).
42+
- MariaDB server.
4443
- An SQL client tool like `mariadb`, DBeaver, or an SQL integration for
4544
your IDE.
4645

47-
## Running the app
48-
49-
Prepare the database:
46+
## Preparing the database
5047

51-
```sql
52-
CREATE DATABASE demo;
53-
CREATE USER 'user'@'%';
54-
GRANT ALL ON demo.* TO 'user'@'%' IDENTIFIED BY 'password';
48+
See the instructions [here](../../README.md).
5549

56-
57-
USE demo;
58-
CREATE TABLE programming_language(
59-
name VARCHAR(50) NOT NULL UNIQUE,
60-
rating INT
61-
);
62-
```
50+
## Running the app
6351

6452
Run the following from the command line:
6553

66-
```
54+
```Shell
6755
git clone [email protected]:mariadb-developers/java-quickstart.git
6856
cd java-quickstart/jdbc/part2/
6957
mvn package
7058
java -jar java -jar target/jdbc-demo-1.0-SNAPSHOT.jar
7159
```
7260

61+
## Check the output
62+
63+
You should see the output in the terminal.
64+
65+
You can also connect to the database and see the data in the `programming_language` table:
66+
67+
```shell
68+
mariadb-shell --dsn mariadb://user:'Password123!'@127.0.0.1
69+
```
70+
71+
Run the following query:
72+
73+
```SQL
74+
SELECT * FROM demo.programming_languages;
75+
```
76+
7377
## Tutorial
7478

7579
Read the [tutorial](https://dzone.com/articles/jdbc-tutorial-part-2-running-sql-queries) or watch the video for detailed steps on how to implement this example from scratch:

jdbc/part2/src/main/java/com/example/Application.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.example;
22

3-
import java.sql.*;
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.PreparedStatement;
6+
import java.sql.ResultSet;
7+
import java.sql.SQLException;
48

59
public class Application {
610

@@ -102,13 +106,6 @@ private static void initDatabaseConnection() throws SQLException {
102106
"jdbc:mariadb://localhost:3306/demo",
103107
"user", "Password123!");
104108
System.out.println("Connection valid: " + connection.isValid(5));
105-
/*
106-
* If you are using MariaDB SkySQL (https://mariadb.com/products/skysql),
107-
* enable SSL and specify the path to the CA chain file that you can download
108-
* from the SkySQL Portal (https://cloud.mariadb.com):
109-
* jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/demo?sslMode=verify-ca&
110-
* serverSslCert=/path/to/your/skysql_chain.pem
111-
*/
112109
}
113110

114111
private static void closeDatabaseConnection() throws SQLException {

jdbc/part3/README.md

+20-24
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ dataSource.username=user
2323
dataSource.password=Password123!
2424
```
2525

26-
> If you are using [MariaDB SkySQL](https://mariadb.com/products/skysql/), enable SSL and specify the path to the CA chain file that you can download from the [SkySQL Portal](https://cloud.mariadb.com):
27-
>
28-
> `jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/database_name?sslMode=verify-ca&serverSslCert=/path/to/your/skysql_chain.pem`
29-
3026
Create a `DataSource` at application start:
3127

3228
```java
@@ -50,40 +46,40 @@ dataSource.close();
5046

5147
## Requirements
5248

53-
- Java 17 or later. Previous versions should work (update the version
49+
- Java 21 or later. Previous versions should work (update the version
5450
in the **pom.xml** file).
5551
- [Apache Maven](https://maven.apache.org).
56-
- MariaDB server. If you don't want to install
57-
anything extra, try creating a free [SkySQL account](https://cloud.mariadb.com).
52+
- MariaDB server.
5853
- An SQL client tool like `mariadb`, DBeaver, or an SQL integration for
5954
your IDE.
6055

61-
## Running the app
62-
63-
Prepare the database:
64-
65-
```sql
66-
CREATE DATABASE demo;
67-
CREATE USER 'user'@'%';
68-
GRANT ALL ON demo.* TO 'user'@'%' IDENTIFIED BY 'password';
56+
## Preparing the database
6957

58+
See the instructions [here](../../README.md).
7059

71-
USE demo;
72-
CREATE TABLE programming_language(
73-
name VARCHAR(50) NOT NULL UNIQUE,
74-
rating INT
75-
);
76-
```
60+
## Running the app
7761

7862
Run the following from the command line:
7963

80-
```
64+
```Shell
8165
git clone [email protected]:mariadb-developers/java-quickstart.git
8266
cd java-quickstart/jdbc/part3/
8367
mvn package
8468
java -jar java -jar target/jdbc-demo-1.0-SNAPSHOT.jar
8569
```
8670

87-
## Tutorial
71+
## Check the output
8872

89-
*(Work in progress. Stay tuned!)*
73+
You should see the output in the terminal.
74+
75+
You can also connect to the database and see the data in the `programming_language` table:
76+
77+
```shell
78+
mariadb-shell --dsn mariadb://user:'Password123!'@127.0.0.1
79+
```
80+
81+
Run the following query:
82+
83+
```SQL
84+
SELECT * FROM demo.programming_languages;
85+
```

jdbc/part3/src/main/resources/database.properties

-6
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,3 @@
22
jdbcUrl=jdbc:mariadb://127.0.0.1:3306/demo
33
username=user
44
password=Password123!
5-
6-
# If you are using MariaDB SkySQL (https://mariadb.com/products/skysql),
7-
# enable SSL and specify the path to the CA chain file that you can download
8-
# from the SkySQL Portal (https://cloud.mariadb.com):
9-
#
10-
# jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/demo?sslMode=verify-ca&serverSslCert=/path/to/your/skysql_chain.pem

0 commit comments

Comments
 (0)