{"id":24617662,"url":"https://github.com/pacphi/jdbc-demo","last_synced_at":"2026-04-11T11:04:09.548Z","repository":{"id":48353124,"uuid":"138527493","full_name":"pacphi/jdbc-demo","owner":"pacphi","description":"This is a simple experiment to test a Spring Boot/MVC interaction against a PostgreSQL instance via the Postgres JDBC driver.","archived":false,"fork":false,"pushed_at":"2021-07-30T13:15:07.000Z","size":92,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-24T23:39:39.777Z","etag":null,"topics":["java","jdbc","postgresql","spring-boot-2","spring-mvc"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pacphi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-25T01:01:52.000Z","updated_at":"2020-07-15T17:55:55.000Z","dependencies_parsed_at":"2022-08-29T17:11:23.306Z","dependency_job_id":null,"html_url":"https://github.com/pacphi/jdbc-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Fjdbc-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Fjdbc-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Fjdbc-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Fjdbc-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pacphi","download_url":"https://codeload.github.com/pacphi/jdbc-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244308672,"owners_count":20432248,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jdbc","postgresql","spring-boot-2","spring-mvc"],"created_at":"2025-01-24T23:39:50.963Z","updated_at":"2026-04-11T11:04:09.524Z","avatar_url":"https://github.com/pacphi.png","language":"Java","readme":"# JDBC Experiment  \n\nThis is a simple experiment to test a [Spring Boot/MVC](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc) interaction against a [PostgreSQL](https://www.postgresql.org) instance via the Postgres JDBC [driver](https://jdbc.postgresql.org). \n\n\u003e I am the older brother of [Reactive ~~JDBC~~ Experiment](https://github.com/pacphi/reactive-jdbc-demo).\n\n## Prerequisites\n\n* An account with [Space Developer role](https://docs.cloudfoundry.org/concepts/roles.html#roles) access on a Cloud Foundry foundation, e.g., [Pivotal Web Services](https://run.pivotal.io)\n* [CF CLI](https://github.com/cloudfoundry/cli#downloads) 6.37.0 or better if you want to push the application to a Cloud Foundry (CF) instance\n* [httpie](https://httpie.org/#installation) 0.9.9 or better to simplify interaction with API endpoints\n* Java [JDK](https://adoptium.net/) 21 or better to compile and run the code\n* [Gradle](https://gradle.org/releases/) 9.1 or better to build and package source code (wrapper included)\n* Docker for [Mac](https://store.docker.com/editions/community/docker-ce-desktop-mac) or [Windows](https://store.docker.com/editions/community/docker-ce-desktop-windows) for spinning up a local instance of Postgres and Adminer (a database administration interface)\n\n\n## Clone\n\n```bash\ngit clone https://github.com/pacphi/jdbc-demo.git\n```\n\n## How to build\n\n```bash\ncd jdbc-demo\ngradle build\n```\n\n## How to run locally \n\n1. Prepare database\n\n    Open a Terminal session, then type\n\n    ```bash\n    docker-compose up -d\n    ```\n\n2. Login to [Adminer](https://www.adminer.org) interface \n\n    Open a browser and visit `http://localhost:9090`\n\n    Credentials are:\n\n    * System =\u003e `PostgreSQL`\n    * Server =\u003e `db`\n    * Username =\u003e `admin`\n    * Password =\u003e `passw0rd`\n    * Database =\u003e `people`\n\n    Click the `Login` button\n\n    \u003e At this point we're just verifying that you can connect to the database instance successfully.\n\n3. Start the application\n\n    Start a new Terminal session and type\n\n    ```bash\n    gradle bootRun \\\n    -Dspring.datasource.url=jdbc:postgresql://localhost:5432/people \\\n    -Dspring.datasource.username=admin \\\n    -Dspring.datasource.password=passw0rd \\\n    -Dspring.datasource.driver-class-name=org.postgresql.Driver \n    ```\n\n4. Let's create some data using the API\n\n    ```bash\n    http POST localhost:8080/person firstName=Dweezil lastName=Zappa age=48\n\n    HTTP/1.1 201 Created\n    Content-Length: 0\n    Date: Mon, 25 Jun 2018 00:36:35 GMT\n    Location: /person/582279d1-9bd1-4e49-946c-ac720de0e04f\n    ```\n\n5. Verify that we can find the person we added\n\n    ```bash\n    http localhost:8080/person\n\n    HTTP/1.1 200 OK\n    Content-Type: application/json\n    transfer-encoding: chunked\n\n    [\n        {\n            \"age\": 48,\n            \"firstName\": \"Dweezil\",\n            \"id\": \"582279d1-9bd1-4e49-946c-ac720de0e04f\",\n            \"lastName\": \"Zappa\"\n        }\n    ]\n    ```\n\n6. Let's ask for a person by id\n\n    ```bash\n    http localhost:8080/person/582279d1-9bd1-4e49-946c-ac720de0e04f\n\n    HTTP/1.1 200 OK\n    Content-Length: 95\n    Content-Type: application/json\n\n    {\n        \"age\": 48,\n        \"firstName\": \"Dweezil\",\n        \"id\": \"582279d1-9bd1-4e49-946c-ac720de0e04f\",\n        \"lastName\": \"Zappa\"\n    }\n    ```\n\n## How to shutdown locally\n\n1. Stop the application\n\n    Visit the Terminal session where you started application and press `Ctrl+c`\n\n2. Shutdown Postgres and Adminer interface\n\n    Visit the Terminal session where you invoked `docker-compose-up -d` and type\n\n    ```bash\n    docker-compose down\n    ```\n\n    Note: the data volume is persistent!  If you want to destroy all unused volumes and reclaim some additional space, type\n\n    ```bash\n    docker volume prune\n    ```\n\n## How to run on Cloud Foundry\n\n1. Authenticate to a foundation using the API endpoint. \n    \u003e E.g., login to [Pivotal Web Services](https://run.pivotal.io)\n\n    ```bash\n    cf login -a https:// api.run.pivotal.io\n    ```\n\n2. Push the app, but don't start it\n\n    ```bash\n    cf push jdbc-demo --random-route --no-start -p ./build/libs/jdbc-demo-0.0.1-SNAPSHOT.jar -m 1G -b https://github.com/cloudfoundry/java-buildpack.git\n    ```\n\n3. Let's fire fire up a Postgres instance\n\n    \u003e We're going to use [ElephantSQL](https://www.elephantsql.com)\n\n    ```bash\n    cf cs elephantsql panda {service name}\n    ```\n\n    \u003e Note: this is going to cost you $19/month to keep alive\n    \u003e Replace {service name} above with your desired service name\n\n4. Next we'll bind the service to the application\n\n    ```bash\n    cf bs jdbc-demo {service name}\n    ```\n\n    \u003e Make sure {service name} above matches what you defined in Step 3\n\n5. Let's verify that `VCAP_SERVICES` was properly injected\n\n    ```bash\n    cf env jdbc-demo\n \n    Getting env variables for app jdbc-demo in org scooby-doo / space dev as dweezil@zappa.com...\n    OK\n\n    System-Provided:\n    {\n    \"VCAP_SERVICES\": {\n    \"elephantsql\": [\n    {\n        \"binding_name\": null,\n        \"credentials\": {\n        \"max_conns\": \"20\",\n        \"uri\": \"postgres://mkxolhau:BBB0bLLyWpiUqKozCRhzygyhnpOMlMC@stampy-01.db.elephantsql.com:5432/lankmxwt\"\n        },\n        ...\n    ```\n\n    \u003e We're interested in `vcap_services.elephantsql.uri`\n    \u003e The URI consists of {vendor}://{username}:{password}@{server}:5432/{database}\n\n6. Now let's startup the application\n\n    ```bash\n    cf start jdbc-demo\n    ```\n\n7. Launch Adminer to administer the database\n\n    \u003e We want to verify that we can connect to the database and see that it contains both `flyway_schema_history` and `people` tables\n\n    ```bash\n    docker-compose up -d\n    ```\n\n    Open a browser and visit `http://localhost:9090`\n\n    Credentials are:\n\n    * System =\u003e `PostgreSQL`\n    * Server =\u003e `{server}`\n    * Username =\u003e `{username}`\n    * Password =\u003e `{password}`\n    * Database =\u003e `{database}`\n\n    Replace all bracketed values above with what you learned from Step 5\n\n    Click the `Login` button\n\n8. Follow steps 4-6 above in `How to run locally` to interact with API\n\n    But replace occurrences of `localhost:8080` with URL to application hosted on Cloud Foundry\n\n\n## How to spin down workloads on Cloud Foundry\n\n1. Stop the application\n\n    ```bash\n    cf stop jdbc-demo\n    ```\n\n2. Unbind the database instance\n\n    ```bash\n    cf us jdbc-demo {service name}\n    ```\n    \u003e `{service name}` above should match value in `How to run on Cloud Foundry` steps 3 and 4\n\n3. Delete the database instance\n\n    ```bash\n    cf ds {service name}\n    ```\n    \u003e `{service name}` above should match value in `How to run on Cloud Foundry` steps 3 and 4\n\n4. Delete the application\n\n    ```bash\n    cf delete jdbc-demo\n    ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacphi%2Fjdbc-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacphi%2Fjdbc-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacphi%2Fjdbc-demo/lists"}