Connect databases to HSQLDB Server - hsqldb

I'm using version hsqldb-1.8 in a stand-alone way. I want to start the server with some databases. I'd like to use the command line from the HSQLDB documentation :
java -cp ../lib/hsqldb.jar org.hsqldb.Server -database.0 file:mydb -dbname.0 xdb
My problem is I have the script of each database I need and this command line creates a new database, without using my script. May the problem comes from one of these points :
The location of my script
The extension of my script which is a SQL-file
Something wrong or missing in the command line
The command line can't do it => If yes, is there any way to do it ?
I'd like to stay in the console to do all that. That way, I'll only have to launch a script to do all the job. Any help will be much appreciated ! Thanks

I found the solution of my issue :)
I've created a server.properties file located in the directory ../hsqldb-1.8.10/hsqldb/ which contains that :
server.database.0=file:mydb;user=test;password=test
server.dbname.0=mydb
I've also created the mydb.script file with that code in it:
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
CREATE MEMORY TABLE MYDB(ID BIGINT NOT NULL,VERSION INTEGER NOT NULL,NOM VARCHAR(255))
CREATE USER TEST PASSWORD "TEST"
GRANT DBA TO TEST
SET WRITE_DELAY 10
SET SCHEMA PUBLIC
INSERT INTO MYDB VALUES(1,0,'test')
Then, I launch the HSQLDB Server with this command:
java -cp ../lib/hsqldb.jar org.hsqldb.Server
We can see that the database is successfully created :
[Server#10f0f6ac]: Database [index=0, id=0, db=file:mydb, alias=mydb] opened successfully in 313 ms.
To check if the database really contains my data, I use the HSQLDB DatabaseManager tool with this command:
java -cp ../lib/hsqldb.jar org.hsqldb.util.DatabaseManager
To connect:
URL : jdbc:hsqldb:file:mydb
User : test
Password : test
After that, we are connected to the database. Execute the command SELECT * FROM MYDB; and we can see the line of the database.
Hope that will help ! :)

The easist way to connect with with HSQLDB (IMDB)
Connection String
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:file:/home/vikask/elmo/db/elmo;" />
<property name="username" value="sa" />
<property name="password" value="" />
In this simple Java project to demonstrate Hibernate, HSQL and Maven using Java Annotations. HSQL database is used to make the project simple, as we can use in-memory database and we would need only a JAR file to be included in our project.
To connect to an embedded HSQLDB database, select the JDBC (HSQLDB Embedded) connection type from the connection type list. Enter any login information if applicable, and then specify whether to use an existing embedded database, or to have HSQLDB create a new embedded database.
If the embedded database already exists, browse to the directory where the database files are located (such as database_name.log, database_name.script, and database_name.properties) and select the database_name.script file.
If the database does not exist, type in or browse to create a new location for the HSQLDB database. HSQLDB will then create the necessary files with the prefixed with the database name typed in. For example, if typing /home/vikask/sample as the location of the database, HSQLDB will create a file called sample.properites, and perhaps sample.log, etc. The actual name of the database is simply sample in this case.

HSQLDB creates a file with the .script extension for its internal use. This is not something that you create.
First run the server and connect to one of the databases. The database will be empty at this point. Then use the utilitly, SQLTool which is in the HSQLDB zip package to execute YOUR script on the database. All the tables and data that are created by your script are persisted in the HSQLDB database.

Related

Liquibase - Generating Change Logs

I want Liquibase, to generate a changelog, from this DB 'testing'. Is it possible?
I have an existing database already, with its tables and data inside.
jdbc:mysql://localhost:3306/testing
Now, I want Liquibase, to generate a changelog, from this DB 'testing'. Is it possible?
This is my command, but it doesn't work.
liquibase --driver=com.mysql.jdbc.Driver --classpath=C:\mysql-connector-java-5.1.47.jar
--changeLogFile=C:\db.changelog.xml --url="jdbc:mysql://localhost:3306/testing"
--username=root generateChangeLog
I don't use any password.
The error is related to --changeLogFile=C:\db.changelog.xml
I thought, Liquibase will refer to my DB 'testing', and generate changelog, with name 'db.changelog.xml' in folder C.
Which part I'm wrong? Do I miss something?
Or maybe, Liquibase is not intended, to generate changelog, from existing DB?
Or maybe, Liquibase is intended, to generate DB, from changelog only? And not vice versa?
This is possible. You might be having trouble since you are writing to a file in the root of your c: drive. Try c:\temp\changelog instead.
My experience is that liquibase works in increments. So if you run that command on your database, it will produce a file as if everything in the database has to be created in the changelog file (as if starting with a completely empty database).
If you read the text on Liquibase's site regarding this command, it says:
When starting to use Liquibase on an existing database, it is often useful, particularly for testing, to have a way to generate the change log to create the current database schema.
This means that if you:
Execute this command once against your dev database
Run the result against a new database (let's say test)
Run it again on your dev database
Run that file against your test database
You will get a load of errors stating that functions already exist.
I gather that the idea behind this is that you create new entries in the changelog files and executing them against ALL your databases, instead of using other tools and using liquibase for the delta.
Sample entry
<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat" schemaName="public" tableName="YY">
<column name="xx" type="varchar(255)"/>
</addColumn>
</changeSet>
SQL equivalent
ALTER TABLE yy ADD COLUMN xx INT

getting started with liquibase on snowflake

I am trying to get started with liquibase on snowflake.
I think I am almost there with the liquibase.properties file
driver: net.snowflake.client.jdbc.SnowflakeDriver
classpath: ./liquibase-snowflake-1.0.jar
url: jdbc:snowflake://XXXXXX.us-east-1.snowflakecomputing.com
username: YYYYYYYYY
password: ZZZZZZZZZZ
changeLogFile: mySnowflakeChangeLog.xml
Unfortunately, liquibase complains about not having a "current database" when trying to create the tables databasechangelog and/or databasechangeloglock.
Since, I do not have access to the sql script creating these database tables, how do I instruct liquibase which DATABASE to use?
I pinged an internal team here #Snowflake. They recommended:
adding db=mydb database connection parameter to the URL.. or set
default namespace for the user.. alter user mike set
default_namespace=mydb
Hope that helps!
I am not an expert in liquibase, but JDBC standard allows custom connection properties being passed in. If liquibase support that, you can specify database as a custom connection property, and Snowflake JDBC will pass the database information with create connection request sending to the server.

How to create a persistence HSQL database?

I am new to HSQLDB and want to create a persistent database so that when opening HSQLDB, the already created tables with their contents exist. I read about HSQLDB in the documentation, but cannot find the information. My current HSQLDB.bat is the following:
cd %HSQLDB%
java -cp ../lib/hsqldb.jar org.hsqldb.util.DatabaseManagerSwing
REM java -cp ../lib/hsqldb.jar org.hsqldb.server.Server
REM java -classpath lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:hsqldb/demodb --dbname.0 testdb
When running the batch, the following dialogue opens:
Note that the URL filed contains jdbc:hsqldb:mem:..
After [OK], I call two scripts, one creating two tables, the other filling them with test data. But reopening HSQLDB does not read the tables with their data.
What is missing, what is wrong? A SHUTDOWN does not change anything. I also replaced mem with file, but could not make the database persistent. What did I oversee in the HSQLDB guide?
Use the drop-down list for Type: and select HSQL Database Engine Standalone, then edit the suggested URL to add your database file path such as jdbc:hsqldb:file:///C:/Program Files/hsqldb-2.5.0/hsqldb/data/dbname where the last part of the path is the name of the database files.
Absolute paths are preferred to avoid dependency on the directory in which you execute your batch.

Run a initial Liquibase script

This is my 2nd day using Liquibase.
I have a 'backup' or 'Repositry' with the database that I need to create locally on my PC.
I have looked at the documentation, but Im realy not 100% clear on how to run it.
Ive updated the Liquibase.properties file to reflect the correct paths and username and passwords.
How do you run the update command to generate the tables and test data.
Windows 7
The Liquibase documentation on 'Adding Liquibase to an existing project' is probably the best place to start. Basically, you want to set the properties file so that it refers to the existing 'backup' database, and then run liquibase generateChangeLog
This will connect to the existing database and generate a file that contains the structure of the existing database expressed (typically) in an XML file called a changelog. You then create a new properies file that will connect to your local database and use liquibase update to apply the changelog to the local database and populate the structure. Note that this does not typically transfer the data from the existing database to the new database, just the structure - the tables, keys, indexes, etc. If you want to have test data as well, you can either export that data from the existing database, or you might look into crafting the changesets manually. To export the data, a command like this would be used:
java -jar liquibase.jar --changeLogFile="./data/<insert file name> " --diffTypes="data" generateChangeLog

Execute service builder generated sql file on postgresql

I would like to execute sql files generated by the service builder, but the problem is that the sql files contains types like: LONG,VARCHAR... etc
Some of these types don't exist on Postgresql (for example LONG is Bigint).
I don't know if there is a simple way to convert sql file's structures to be able to run them on Postgresql?
execute ant build-db on the plugin and you will find sql folder with vary vendor specific scripts.
Daniele is right, using build-db task is obviously correct and is the right way to do it.
But... I remember a similar situation some time ago, I had only liferay-pseudo-sql file and need to create proper DDL. I managed to do this in the following way:
You need to have Liferay running on your desktop (or in the machine where is the source sql file), as this operation requires portal spring context fully wired.
Go to Configuration -> Server Administration -> Script
Change language to groovy
Run the following script:
import com.liferay.portal.kernel.dao.db.DB
import com.liferay.portal.kernel.dao.db.DBFactoryUtil
DB db = DBFactoryUtil.getDB(DB.TYPE_POSTGRESQL)
db.buildSQLFile("/path/to/folder/with/your/sql", "filename")
Where first parameter is obviously the path and the second is filename without .sql extension. The file on disk should have proper extension: must be called filename.sql.
This will produce tables folder next to your filename.sql which will contain single tables-postgresql.sql with your Postgres DDL.
As far as I remember, Service Builder uses the same method to generate database-specific code.