Springboot In memory hsqlDb cannot see tables from sql browser - spring-boot

I am using in memory hsqldb in my spring boot project. Here is a sample of my appliction.properties
spring.datasource.url=jdbc:hsqldb:mem
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
When I start my application, it creates couple of files like mem.script, mem.log in my project home directory.
mem.log has all the sql statements it has excuted on the database. And it gets updated whenever some action is triggered from my repository class. Functionality as a whole is working, I can even query from this hsqldb and it works.
But for some debugging purpose I want to connect to this db through some db client (DBVisualizer). When I tried connecting(DB Type : HSQLDB Embedded) using this mem.log file, I was successfully connected, but cannot see any of my tables there.
I even tried setting up a server in my application as mentioned here,
How to start HSQLDB in server mode from Spring boot application
Even in this case I can connect from DBVisualizer(DB Type : HSQLDB Server) but cannot see any tables.
Please let me know if I am missing something.
Thanks

First of all, the url you are using is too similar to an all-in-memory database with no files (jdbc:hsqldb:mem:anyname) but it is not an in-memory URL.
Follow the the instructions for the server mode in the question you linked to. Report your version of the configuration if you cannot see the tables. Note the configuration parameters that I quote below:
<prop key="server.database.0">mem:testdb</prop>
<prop key="server.dbname.0">testdb</prop><!--DB name for network connection-->
and connect with this URL from DBVisualiser
jdbc:hsqldb:hsql://localhost/testdb

Related

Log effective URL for Spring Boot Liquibase

I'm using Spring Boot 2.7. When I run a unit test, it insists on creating the Liquibase change log table either twice for what should be an H2 in memory database. I'd like to have Liquibase log the actual JDBC URL being used. I know what the properties say, but I have an application.properties, an application-h2.properties, and sometimes Spring wants to use an in memory database even though a different in memory database is used.
Is there some property like
spring.liquibase.show-effective-jdbc-url=true?
Bonus points for telling me how to log this for regular JPA access.
Thanks,
Woodsman
There is not a flag, but the effective URL is logged at FINE level. There should be a message like Connected to USER#URL where the value for url is returned from the driver itself, not just what you gave it.

Wildfly using h2 for datasource instead of driver I specified

I added ojdbc6.jar driver to Wildfly as a deployment, and created a datasource which uses the ojdbc6.jar driver. This worked and I was able to access the database in my project - displaying info from the database using a servlet.
However when I restarted my computer it no longer worked (but I hadn't changed anything) and was throwing me org.h2.jdbc.JdbcSQLException even though I am not trying to connect to the h2 database.
So basically Wildfly seems to keep overwriting the setting for my Datasource to use the ojdbc6 driver and changing it to use the h2 driver and I don't know how to stop this.
Can anyone help?
I have seen online for this problem about editing a persistence.xml file but I don't have one.. should I create one?

Can anyone explain detailed use of persistent.xml file in hibernate JPA project?

I have read articles about hibernate -JPA on the internet but unable to understand how it used and how it is working in the background for hibernate. Also, need information about what should be the name of a persistent unit in persistent.xml and what is the use of it?
Mainly we use persistnce.xml / hibernate.cfg.xml to tell hibernate the following details
What Database you're using? so, that hibernate executes all the queries w.r.t that Database
Connecting to Database like Providing Username and password
The database name
Hibernate mapping files name and many more
Go through this link

Connect to existing hsqldb instance in IDE

I am learning Spring Boot using open-source projects and have stumbled upon their demo project — PetClinic. It has two possible databases configured: MySQL & HSQLDB, it uses the latter by default.
So I was able to launch the project look at it on localhost and can see that the DB (HSQLDB) is being populated but I was unable to set up a connection through the Intellij IDEA because the project does not specify the path that allows to see the contents of this in-memory DB.
Can anyone please tell me, what am I missing in the process of establishing the connection to HSQLDB here?
Thanks!
You can't connect to an in-memory instance of HSQLDB from another process.
The main drawback [of in-memory mode] is that it is not possible by default to connect to
the database from outside your application. As a result you cannot
check the contents of the database with external tools such as
Database Manager while your application is running.
If you want to do this, you need to run HSQL as a server. More details about how to run it in server mode can be found here.

(Spring Boot and H2) Can't use h2 database

I'm learning Spring boot and I'm trying to create a very simple RESTful API that access an in-memory database and perform CRUD actions.
However, everytime I try to Connect or Test Connection on http://localhost:8080/h2-console, I get this error:
"Database "C:/Users/XXX/test" not found, and IFEXISTS=true, so we cant auto-create it [90146-199] 90146/90146"
https://imgur.com/a/oYgkK1C
I followed EXACTLY the instructions from http://www.springboottutorial.com/spring-boot-crud-rest-service-with-jpa-hibernate. I have tried everything I could find online: using jdbc:h2:mem:test as JDBC URL etc, but none of them worked for me and I'm not sure what am I doing wrong.
I didn't install h2 database from the official website as I read it is not necessary to use the in-memory module (and I still don't know if I should've installed it or not, as there is not a single mention of it online, as far as I checked).
Any thoughts? I'm a beginner when it comes to Spring Boot and I'm really lost. I just want to test CRUD actions and I don't care about the persistence of the DB.
I have provided my application.properties below.
Thank you! :)
# H2
spring.h2.console.enabled=true
spring.h2.console.path=/h2
# Datasource
spring.datasource.url=jdbc:h2:mem:test
spring.datasource.username=user
spring.datasource.password=user
spring.datasource.driver-class-name=org.h2.Driver
Make sure your url in h2-console(refer screenshot below) is same as your 'spring.datasource.url=jdbc:h2:mem:test'.
It worked for me.
UPDATE: Other alternative solution is,
you can avoid setting spring.datasource.url property. Spring will automatically set this default JDBC url for you.
happy learning.. Upvote, if it is sovled your issue.
In your spring application.properties file, set the property
spring.datasource.url=jdbc:h2:~/test
Then restart the application and open http://localhost:8080/h2-console/
Click on Test Connection button, you should see "Test successful".

Resources