# Having problems rendering my database entries on a html page

**URL:** https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259
**Category:** How to?
**Tags:** clojure
**Created:** [October 8, 2021, 3:37pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259 "2021-10-08T15:37:16Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![wolfdale229](https://clojureverse.org/user_avatar/clojureverse.org/wolfdale229/32/3892_2.png) [@wolfdale229](https://clojureverse.org/u/wolfdale229)
#### Post date: [October 8, 2021, 3:37pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/1 "2021-10-08T15:37:16Z")

</div>

Hi guys, i have been learning clojure for the last four months now (this is my first serious attempt at programming), right now i am following @seancorfield advice  
“ClojureScript stuff and just start with a very simple Ring app, then add Hiccup for HTML generation (or Selmer, my preference), then add Compojure or Bidi for routing, then maybe add `next.jdbc` to work with a database. Take things one step at a time, understanding each step as you go.”  
so this past week i have tried building a guest-book application, i started with building the server, then added routing with compojure, then used selmer for HTML generation. All this have worked fine until i wanted to add database functionality. i have setup my database spec and some functions to perform necessary operation (I’m using h2 for database and next.jdbc library).  
Here is a snapshot project.clj, database and views.clj files

 ![2021-10-08-161956_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/7/7c2ad99068550630bdbf766c4e1832aff154f20f.png)

 ![2021-10-08-162930_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/8/8a34b35860f763874d1d362483fae16645324d39.png)

 ![2021-10-08-163209_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/f/f111497a656eeae0a2ac02cc1d1e1b4eac0bcfbc.png)

Going to the url on my browser i get this

 ![2021-10-08-163447_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/9/9dd32e66a6a46ec6b2b34ce7ae0f7ce3b22a83d3.png)

Instead of something similar to this

 ![2021-10-08-163716_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/9/9004e0d0d7dba75471733f15e341cf94ae8fc1e2.png)

So guys what am i doing wrong/ what haven’t i learnt correctly.

---

<div class="post-metadata">

### Author: ![wolfdale229](https://clojureverse.org/user_avatar/clojureverse.org/wolfdale229/32/3892_2.png) [@wolfdale229](https://clojureverse.org/u/wolfdale229)
#### Post date: [October 8, 2021, 3:39pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/2 "2021-10-08T15:39:26Z")

</div>

Here is my index.html page

 ![2021-10-08-164103_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/2/2143a4dab89637ec2404e05575825d0c99838d46.png)

---

<div class="post-metadata">

### Author: ![ProfoundBoat](https://clojureverse.org/user_avatar/clojureverse.org/profoundboat/32/3829_2.png) [@ProfoundBoat](https://clojureverse.org/u/ProfoundBoat)
#### Post date: [October 8, 2021, 5:05pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/3 "2021-10-08T17:05:23Z")

</div>

It helps to consider each link in the chain between what you see and the database. Start at one end and try to rule out that it’s an issue, then go one more link in until you hit the connection that’s a problem (or discover the bug.)

I’d start with the DB connection. Instead of pulling out specific fields from the message items, can you print the whole item to verify that you’re getting them in the shape your template expects?

---

<div class="post-metadata">

### Author: ![seancorfield](https://clojureverse.org/user_avatar/clojureverse.org/seancorfield/32/195_2.png) [@seancorfield](https://clojureverse.org/u/seancorfield)
#### Post date: [October 8, 2021, 6:01pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/4 "2021-10-08T18:01:47Z")

</div>

This is good advice for debugging the problem – one step at a time – it’s often very helpful to put `println` calls into your code to see what the data actually looks like at each place. Displaying `{{item}}` in your template will probably also be helpful, since that will show what keys are available and their values.

Since you are seeing three `Created` bullets, that tells you that `messages` has three entries in it – so you’re getting expected _amount_ of data but the three fields you are trying to display are not present with those names (so you’re getting `nil` which Selmer renders as an empty string).

It might help you at this point to work through the [**Getting Started** guide for `next.jdbc`](https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.2.731/doc/getting-started) in a REPL session to see what the data looks like.

---

<div class="post-metadata">

### Author: ![wolfdale229](https://clojureverse.org/user_avatar/clojureverse.org/wolfdale229/32/3892_2.png) [@wolfdale229](https://clojureverse.org/u/wolfdale229)
#### Post date: [October 8, 2021, 6:03pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/5 "2021-10-08T18:03:28Z")

</div>

> [@ProfoundBoat](#):
>
> Instead of pulling out specific fields from the message items, can you print the whole item to verify that you’re getting them in the shape your template expects?

Trying the above gave me the right output

 ![2021-10-08-190358_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/2/2c28838dd35cf940313a2f2acf3fcd900859196f.png)  
 ![2021-10-08-190401_1366x768_scrot](https://clojureverse.org/uploads/default/original/2X/e/e3f87c7354cc9204832d174d86f986861f1df23a.png)

---

<div class="post-metadata">

### Author: ![ProfoundBoat](https://clojureverse.org/user_avatar/clojureverse.org/profoundboat/32/3829_2.png) [@ProfoundBoat](https://clojureverse.org/u/ProfoundBoat)
#### Post date: [October 8, 2021, 6:24pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/6 "2021-10-08T18:24:42Z")

</div>

It looks like your data has keys like `:GUEST_BOOK/MESSAGE` rather than `:message`. Do the references to item fields in your template need to be adjusted from `item.message` to something like `item.GUEST_BOOK/MESSAGE`?

---

<div class="post-metadata">

### Author: ![wolfdale229](https://clojureverse.org/user_avatar/clojureverse.org/wolfdale229/32/3892_2.png) [@wolfdale229](https://clojureverse.org/u/wolfdale229)
#### Post date: [October 9, 2021, 6:16am UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/7 "2021-10-09T06:16:55Z")

</div>

Thanks guys, i have been able to solve it

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [April 9, 2022, 6:17pm UTC](https://clojureverse.org/t/having-problems-rendering-my-database-entries-on-a-html-page/8259/8 "2022-04-09T18:17:23Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
