Change H2 Database to SQL database in spring boot - sql

I am learning Spring boot by myself. Now I am using H2 database in my spring boot application.
How do I change H2 database to SQL database?
Is there any other application need to install for using SQL database?

No, you just need to add corresponding dependencies with the DB and then update the application.properties file with the new configuration of your desired DB.
Look at this to work with MySQL:
https://mkyong.com/spring-boot/spring-boot-spring-data-jpa-mysql-example/
Or you may want to use different profiles with different DBs (eg: H2 & MySQL)
See this: https://www.baeldung.com/spring-profiles

Related

Migrate from H2 to PostgreSQL

I need to replace H2 with PostgreSQL at the WSO2 API Manager. Since there is currently data saved on H2, I need to pass it to PostgreSQL.
I found the command
SCRIPT TO 'dump.sql'
to export the data to .sql files, but I could not use it because I was not given the credentials to access the database, so I had to retrieve the data from the .mv.db files that H2 generates. On those files the data is not encrypted, but the password obviously is. To export the data to .sql files I used the command
java -cp h2-*.jar org.h2.tools.Recover -dir file_path -db file_name.
The .sql files are generated correctly, but when I try to import them into PostgreSQL with the command
psql -U db_user db_name < dump_name.sql
numerous syntax errors come up, probably due to the imcompatibility of H2 and PostgreSQL dialects. Is there a way to export the data so that it can then be imported into PostgreSQL? Alternatively, would there be an alternative way to migrate the data?
This is changing the database vendor and we don't support such use cases. There are different scripts in the /[PRODUCT_HOME]/dbscripts folder and you need to setup the target database (in your case PostgreSQL) using the correct scripts. This is due to the nature of differences between different database vendors. The datatypes and schema are different from one database vendor to another.
The correct approach is to go through the migration. You can setup a new environment with PostgreSQL and use a 3rd-party tool or a tool provided by the database vendor to migrate data from H2 to ProstgreSQL. There is no straightforward method to change the database from H2 to PostgreSQL.
For more information on the product migration - https://apim.docs.wso2.com/en/latest/install-and-setup/upgrading-wso2-api-manager/upgrading-guidelines/
WSO2 does not have any scripts or tools for cross-db migrations. However, you can use the API controller[1] to migrate APIs, Applications from the previous environment with H2 DB to a new one with PostgreSQL.
[1] - https://apim.docs.wso2.com/en/latest/install-and-setup/setup/api-controller/getting-started-with-wso2-api-controller/

Is H2 database Replaceable

I have been working on ApacheIgnite in my organization.
Somewhere i have read that apacheignite is tightly coupled with h2 database .
Can I change h2 database to some other database in apache Ignite.
Ignite does not use H2 to store or index data, it just uses H2's query parser, query planner and serialization, with a lot of customization over either one.
So you can't replace H2 dependency, but if what you really want is storing data in 3rd party database, then you can certainly do that via 3rd Party Persistence.

a large dataset to test apache ignite?

I am new to Apache Ignite. Can you please suggest a way to get a large data set (preferably CSVs along with DDL statements that is Ignite compliant), which I could use it to create schema, tables in Ignite (uses native persistence), to test a few use cases that I have.
You can use Web Console to copy data from relational DB into Apache Ignite, creating data structure and project files along the way.
Apply it on existing database or something like MySQL Employees sample database.
Web Console will connect to existing internally deployed Database using 'agent' program ran locally.

Multiple databases with NHibernate

I have the following scenario - Our desktop application talks to a SQL Server on another machine. We are using Nhibernate 2.1.2. Now, we want to use SQLite on client machine to store data which could not be uploaded. For example, if Order table has not been updated on SQL Server, we want to save it to SQLite. And, then later try to upload to SQL Server. So, we are thinking to use Nhibernate for storing data in SQLite. How do I configure NHibernate to achieve this?
thanks
You will need to create a whole new session/session source. NHibernate can not simply switch contexts with the push of a button. Best bet is to spin up a separate repository and session that point at that specific second database.

Viewing a grails schema while it runs in memory?

I want to view a grails schema for the default hsqldb in-memory database, but when I connect to the in-memory databse with SquirrelSQL or DbVisualizer as userid: sa, password: (nothing), I only see two schemas:
INFORMATION_SCHEMA
PUBLIC
And neither contains my Domain tables. What's going on?
You need to set the hsqldb database to file, and set shutdown to true, as outlined here.
If you want to access the in-memory database, there's a writeup on how to do that here: http://act.ualise.com/blogs/continuous-innovation/2009/07/viewing-grails-in-memory-hsqldb/
There's also a new plugin that gives you access to a web-based database console that can access any database that you have a JDBC driver for, including the in-memory hsql db. The plugin docs are at http://grails.org/plugin/dbconsole and you install it the usual way, i.e. grails install-plugin dbconsole. Unfortunately the plugin has an artificial restriction to Grails 1.3.6+, so if you're using an older version of Grails you can use the approach from the blog post that inspired the plugin, http://burtbeckwith.com/blog/?p=446
To use the database console, select "Generic HSQLDB" from the settings dropdown and change the values to match what's in DataSource.groovy. This will probably just require changing the url to jdbc:hsqldb:mem:devDB
You need to set up a shared hsql database: Creating a shared HSQLDB database
edit: There is NO way to expose in-memory hsqldb. Either create a Server or WebServer or use file URL.