Skip to content

Commit dabe6da

Browse files
committed
Updated jOOQ example
1 parent 42f596f commit dabe6da

File tree

5 files changed

+21
-31
lines changed

5 files changed

+21
-31
lines changed

jakarta-ee/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Execute the following SQL statements to create a user for the JakartaEE applicat
9797
```sql
9898
CREATE DATABASE demo;
9999
CREATE USER 'user'@'%' IDENTIFIED BY 'Password123!';
100-
GRANT SELECT, INSERT, UPDATE, DELETE ON demo.* TO 'user'@'%';
100+
GRANT SELECT, INSERT, UPDATE, DELETE, DROP ON demo.* TO 'user'@'%';
101101

102102
USE demo;
103103
CREATE TABLE programming_language(

spring-boot-jooq/README.md

+11-15
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ spring.datasource.username=user
2929
spring.datasource.password=password
3030
```
3131

32-
> 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):
33-
>
34-
> `jdbc:mariadb://demo-db0000xxxx.mdb000xxxx.db.skysql.net:5047/jooq_demo?sslMode=verify-ca&serverSslCert=/path/to/your/skysql_chain.pem`
35-
3632
Autowire a `DSLContext` and use it to run SQL statements:
3733

3834
```java
@@ -45,25 +41,25 @@ List<ProgrammingLanguageRecord> programmingLanguages = dslContext
4541
```
4642

4743
## Requirements
48-
- Java 17 or later. Previous versions should work (update the version in the pom.xml file).
49-
Apache Maven.
50-
- MariaDB server. If you don't want to install anything extra, try creating a free [SkySQL account](https://cloud.mariadb.com).
51-
- An SQL client tool like mariadb, DBeaver, or an SQL integration for your IDE.
44+
- Java 21 or later. Previous versions should work (update the version in the pom.xml file).
45+
Apache Maven
46+
- MariaDB server
47+
- An SQL client tool like mariadb, DBeaver, or an SQL integration for your IDE
5248

5349
## Running the app
5450

5551
Prepare the database:
5652

5753
```sql
58-
CREATE DATABASE jooq_demo;
59-
CREATE USER 'user'@'%';
60-
GRANT ALL ON jooq_demo.* TO 'user'@'%' IDENTIFIED BY 'password';
61-
54+
CREATE DATABASE demo;
55+
CREATE USER 'user'@'%' IDENTIFIED BY 'Password123!';
56+
GRANT SELECT, INSERT, UPDATE, DELETE, DROP ON demo.* TO 'user'@'%';
6257

63-
USE jooq_demo;
58+
USE demo;
6459
CREATE TABLE programming_language(
65-
name VARCHAR(50) NOT NULL UNIQUE,
66-
rating INT
60+
pl_id INT PRIMARY KEY AUTO_INCREMENT,
61+
pl_name VARCHAR(50) NOT NULL UNIQUE,
62+
pl_rating INT
6763
);
6864
```
6965

spring-boot-jooq/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.springframework.boot</groupId>
66
<artifactId>spring-boot-starter-parent</artifactId>
7-
<version>2.6.6</version>
7+
<version>3.1.5</version>
88
<relativePath /> <!-- lookup parent from repository -->
99
</parent>
1010
<groupId>com.example</groupId>
@@ -13,7 +13,7 @@
1313
<name>spring-boot-jooq</name>
1414
<description>Demo project for Spring Boot</description>
1515
<properties>
16-
<java.version>17</java.version>
16+
<java.version>21</java.version>
1717
</properties>
1818
<dependencies>
1919
<dependency>

spring-boot-jooq/src/main/java/com/example/springbootjooq/Application.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void createProgrammingLanguages() {
4747
Arrays.stream("Java,C++,C#,JavaScript,Rust,Go,Python,PHP".split(","))
4848
.forEach(name -> {
4949
dslContext.insertInto(PROGRAMMING_LANGUAGE)
50-
.columns(PROGRAMMING_LANGUAGE.NAME, PROGRAMMING_LANGUAGE.RATING)
50+
.columns(PROGRAMMING_LANGUAGE.PL_NAME, PROGRAMMING_LANGUAGE.PL_RATING)
5151
.values(name, (int) (Math.random() * (10 - 3 + 1)) + 3)
5252
.execute();
5353
});
@@ -57,14 +57,14 @@ public void printTopProgrammingLanguages(int rating) {
5757
System.out.println("Top programming languages:");
5858

5959
List<ProgrammingLanguageRecord> programmingLanguages = dslContext
60-
.select(PROGRAMMING_LANGUAGE.NAME, PROGRAMMING_LANGUAGE.RATING)
60+
.select(PROGRAMMING_LANGUAGE.PL_NAME, PROGRAMMING_LANGUAGE.PL_RATING)
6161
.from(PROGRAMMING_LANGUAGE)
62-
.where(PROGRAMMING_LANGUAGE.RATING.greaterThan(rating))
63-
.orderBy(PROGRAMMING_LANGUAGE.RATING.desc())
62+
.where(PROGRAMMING_LANGUAGE.PL_RATING.greaterThan(rating))
63+
.orderBy(PROGRAMMING_LANGUAGE.PL_RATING.desc())
6464
.fetchInto(ProgrammingLanguageRecord.class);
6565

6666
programmingLanguages.stream()
67-
.map(pl -> pl.getName() + ": " + pl.getRating())
67+
.map(pl -> pl.getPlName() + ": " + pl.getPlRating())
6868
.forEach(System.out::println);
6969
}
7070

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

0 commit comments

Comments
 (0)