Skip to content

Commit

Permalink
add section on docker
Browse files Browse the repository at this point in the history
  • Loading branch information
donsez committed Nov 8, 2024
1 parent cac67b2 commit eeea0fe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
32 changes: 28 additions & 4 deletions jdbc-postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ Duplicate `src/main/java/com/mkyong/jdbc/ListEmployeeExample.java` in `src/main/

Pass the `SQL_SELECT` string as program argument.

First, use `[getObject(int)](https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/ResultSet.html)` for printing the column values.
First, use [`getObject(int)`](https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/ResultSet.html) for printing the column values.

> NB: `boolean wasNull()` - Reports whether the last column read had a value of SQL NULL.

Second, use `[ResultSetMetaData](https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/ResultSetMetaData.html)` for printing the column names in order to beautiful the output.
Second, use [`ResultSetMetaData`](https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/ResultSetMetaData.html) for printing the column names in order to beautiful the output.

```java
ResultSetMetaData metaData = rs.getMetaData();
Expand Down Expand Up @@ -193,6 +193,7 @@ Class theClass = cl.loadClass("org.postgresql.Driver");
```

## Extra : Vérification des vulnérabilités

[Vérification des vulnérabilités](https://mvnrepository.com/artifact/org.owasp/dependency-check-maven) dans le programme Java : https://jeremylong.github.io/DependencyCheck/dependency-check-maven/


Expand All @@ -211,8 +212,31 @@ mvn versions:update-properties
git diff pom.xml
```

## References
* https://jdbc.postgresql.org/documentation/use/
## Extra : Dockerize the program with [`jib` plugin](https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/README.md)

https://www.baeldung.com/jib-dockerizing

> You should have an account on https://hub.docker.com
```bash
export DOCKERHUB_USER=$USER
export IMAGE_PATH=registry.hub.docker.com/$DOCKERHUB_USER/jdbc-jib-app
docker login
mvn compile com.google.cloud.tools:jib-maven-plugin:build -Dimage=$IMAGE_PATH
docker pull $DOCKERHUB_USER/jdbc-jib-app
```

Run the container containing the application
```bash
docker run --rm $DOCKERHUB_USER/jdbc-jib-app
```

What's happen ? Why ?

Re-Run the container containing the application
```bash
docker run --rm --network host $DOCKERHUB_USER/jdbc-jib-app
```

## References
* https://jdbc.postgresql.org/documentation/use/
20 changes: 20 additions & 0 deletions jdbc-postgresql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@
</configuration>
</plugin>

<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<container>
<mainClass>com.mkyong.jdbc.ListEmployeeExample</mainClass>
<!--
<ports>
<port>8080</port>
</ports>
-->
<environment>
<application.title>${project.name}</application.title>
<application.version>${project.version}</application.version>
</environment>
</container>
</configuration>
</plugin>


</plugins>
</build>
</project>

0 comments on commit eeea0fe

Please sign in to comment.