Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java A First Look at Our Todo Project

Alper Yuce
Alper Yuce
12,948 Points

jdbc:h2:tcp vs. jdbc:h2:mem: what are the differences?

I am doing "Our Todo Project". In this workshop, I am learning user authentication, login page, security... I am in the beginning and checking the codes.

I see that in "application.properties" is like;

======================================

todotoday.entity.package = com.teamtreehouse.todotoday.model

todotoday.db.driver = org.h2.Driver

todotoday.db.url = jdbc:h2:mem:todotoday

hibernate.dialect = org.hibernate.dialect.H2Dialect

hibernate.implicit_naming_strategy = org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl

hibernate.format_sql = true

hibernate.show_sql = true

hibernate.hbm2ddl.auto = create-drop

======================================

Under Details for our datasource we define url as "jdbc:h2:mem:todotoday". Can we use "jdbc:h2:tcp://localhost/~/" . What is the main reason we are choosing "mem" instead of tcp? Is it related regarding user authentication?

2 Answers

Anders Björkland
Anders Björkland
7,481 Points

Hi Alper,

I hope more will jump in and discuss since I am very fresh to this. jdbc:h2:mem is an instruction to run the database in-memory. This means that the database is not going to store any data that you might enter into it once you close it. Why anyone might want something like this would be prototyping or testing (and probably other uses as well). You can read more about it at h2database.

Alper Yuce
Alper Yuce
12,948 Points

Thank you Anders for your reply. I was wondering whether I can use tcp for user authentication on this project. Do you have any experience or idea about it?

Anders Björkland
Anders Björkland
7,481 Points

I have no experience yet with that, but it seems like something worthwhile pursuing. I guess some googling, if no one else fills in here, would be something you could do. Maybe page one of the teachers as well?

You can also have alook at the Spring Hibernate Treehouse course which is using h2 on disk.