Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
donsez committed Nov 8, 2024
1 parent f08630a commit 1781084
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions jdbc-postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,64 @@ export PATH=$PATH:~/devtools/apache/apache-maven-3.9.9/bin
mvn -v
```

Install JDBC example
Start the PostgreSQL server using the instructions [here](../postgres/README.md).

Create and populate the `test` database using the [following example](../postgres/work/employee/employee.sql). Password is `changeme` .


Install the JDBC example from https://github.com/mkyong/java-jdbc/

```bash
mkdir -p ~/github/mkyong/
cd ~/github/mkyong/
git clone https://github.com/mkyong/java-jdbc/
```

Build the Jarfile of the program
Build the classes of the program

```bash
cd ~/github/mkyong/
cd java-jdbc/postgresql
mvn install
mvn compile
tree target/classes
ls -al target/*.jar
```

> You can pachage the program as a Jarfile with `mvn compile`.
> You can install the program as a Jarfile with `mvn install` into your local Maven repository `~/.m2/repository`.


Check the classpath of the program
Run the program `src/main/java/com/mkyong/jdbc/JDBCExample.java`
```bash
MAIN_CLASS=com.mkyong.jdbc.JDBCExample
APP_CLASSPATH=./target/classes
java -cp $APP_CLASSPATH $MAIN_CLASS
```

> Question : What's happens ? Why ?

Set the classpath of the program
```bash
APP_CLASSPATH=$(mvn -q exec:exec -Dexec.executable=echo -Dexec.args="%classpath")
echo $APP_CLASSPATH
```

Run the program `src/main/java/com/mkyong/jdbc/JDBCExample.java`
Re-Run the program `src/main/java/com/mkyong/jdbc/JDBCExample.java`
```bash
MAIN_CLASS=com.mkyong.jdbc.JDBCExample
mvn -q exec:java -Dexec.mainClass=$MAIN_CLASS
java -cp $APP_CLASSPATH $MAIN_CLASS
```
or

Re-Run the program `src/main/java/com/mkyong/jdbc/JDBCExample.java` with
```bash
java -cp $APP_CLASSPATH $MAIN_CLASS
MAIN_CLASS=com.mkyong.jdbc.JDBCExample
mvn -q exec:java -Dexec.mainClass=$MAIN_CLASS
```



Run the program `src/main/java/com/mkyong/jdbc/JDBCExample2.java`
```bash
MAIN_CLASS=com.mkyong.jdbc.JDBCExample2
Expand All @@ -74,6 +100,9 @@ or
java -cp $APP_CLASSPATH $MAIN_CLASS
```




## Extra: JDBC URL

Modify the URL `"jdbc:postgresql://127.0.0.1:5432/test"` into the Java classes
Expand Down

0 comments on commit 1781084

Please sign in to comment.