Wednesday, September 20, 2017

1018 Part 1 of Java 8 Code, for editing embedded h2 database tables, record by record

At post No. 1016 at this blog, I have given a php script for editing tables which use Gladius database. From the angle of using php scripts for accessing databases and tables, which do not have passwords, and which do not require much security, Gladius seems to work very efficiently. I might have gone wrong somewhere, but I was unable to work with sql commands of 'alter table xxx alter column', or 'alter table xxx add column', or their equivalent built in Gladius DB functions. Probably, that may be evolving. Normally, for use of php scripts, the three mainstream databases i.e. mysql, postgresql, and sqlite (or sqlite3) seem to be convenient. Among these, sqlite, according to many internet pages, is embeddable. But from my experience I found that (I might have gone wrong somewhere. Readers can correct me), at the stage of development, before distribution by embedding, even sqlite needs installation for adding, modifying, deleting records, creating tables etc. etc. Consequently, I have to temporarily keep aside my searches for php compatible databases, and search for some other platform independent, embeddable databases.

h2 data base seems to be answer

After experimenting with hsqldb, derby, berkeley, and many other databases, at this intermediate stage, I felt comfortable with h2 database for editing tables, and embedding. It does not appear to be pliable with php scripts, and hence, I have tried Java8, for designing a gui, to access an embedded h2 database, for adding records (rows), modifying table records (rows), deleting records (rows) etc. The screenshot in the above jpg image shows the table editor, record by editor.

Getting started with h2 database

H2 database can be downloaded from the following web page:
Click here to go to h2database download page

Using h2 console

The h2 data base comes with a H2 console, which operates in server mode. That means we can open the h2 console in browsers such as Firefox. When the h2.jar (This jar file's name can vary slightly, depending on version name, version date), is invoked with a java -jar command, from Command line, h2 console opens in browser, on its own, with the address: or localhost:8082. Here is a screenshot of the h2 console.

Some 'notes' on experiences from this h2 console

1. jdbc url: jdbc:h2:~/mytest
This 'mytest' is the name of the database, which comes with the h2 database. If we change the database name, a new database gets automatically created. Else, the default database 'mytest' will be opened. If we wish to create a new database in addition to the existing database, we can use a changed name.

2. Default user name which comes with the package is: 'sa'. (Probably it is an abbreviation of 'system administrator'). We can connect to the console using this user name 'sa'. After entering the Console, we can add more users.

3. Default password with the package is: a blank. We can connect to the console using the blank password. After entering the console, if we want, we can change passwords. For our sample developing work we can use default username sa, and blank password.

Now a screenshot after connecting to the h2 console, its default database 'mytest', showing its tables

The default database has one default table given by the h2: 'MY LOVELY STUDENTS'. The other tables tyb1, tyb2, tyb3, tyb4, tyb5, tyb6, tyb6, tyb7, tyb8, tyb9, tyb10 have been created by me for the purpose of our experiment. When you click the + before the table 'MY LOVELY STUDENTS', you will see its columns:

By typing the sql statement 'Select * from MY LOVELY STUDENTS' and clicking the run button, you can see a few rows of the records in the MY LOVELY STUDENTS table.

Continued in Post No. 1019. Click this link to go to 1019, i.e.


  1. This comment has been removed by a blog administrator.

  2. This comment has been removed by a blog administrator.

  3. This comment has been removed by a blog administrator.

  4. Reasons for deleting all the three above comments: Spams. May be machine-bot gnerated. Anyway not connected to our blogs.


ఘోరమైన విమర్శలకు కూడ స్వాగతం, జవాబులు ఇవ్వబడతాయి. Harsh Criticism is also welcome.