Database content not visible in h2 console application

114 views
Skip to first unread message

Jonathan

unread,
Oct 11, 2016, 7:40:45 AM10/11/16
to Lift
Hello,

I would like to adjust the application "liquidizer" (link: https://github.com/liquidizer/liquidizer ). For this I need to see the database's content.

The web application automatically creates the database file lift_proto.db.h2.db if it does not exist. I assume that in this file all data is stored.

In order to see the database's content I followed the steps for viewing the database content in a web browser on this site. I created a user in the liquidizer web application. I should at least see the information about the registered user in the database. Unfortunately, the data base "lift_proto.db.h2.db" seems to be empty when I open it with the h2 console application (see file "empty_h2_database.png").

How can I see the tables of the database used by the liquidizer web application? This post describes the same problem but the solution of putting Schemifier.schemify in the code did not work for me (this is already called by the liquidizer application as you can see in the code below).


class Boot {
 
def boot {

   
if (!DB.jndiJdbcConnAvailable_?) {
      val vendor
=
   
new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
                 
Props.get("db.url") openOr "jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
                 
Props.get("db.user"), Props.get("db.password"))

     
LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)

      DB
.defineConnectionManager(DefaultConnectionIdentifier, vendor)
   
}
   
Schemifier.schemify(true, Schemifier.infoF _, Votable, User, Query,
           
Vote, Comment, Room, Certificate, Emotion, Tick,
               
InviteCode)





empty_h2_database.png

Antonio Salazar Cardozo

unread,
Oct 12, 2016, 8:26:11 AM10/12/16
to Lift
Caveat emptor: I don't know much about H2 or about schemifier.

However, what is the Users thing listed above `H2` in the screenshot? It looks like
the users table that would correspond to the user object, no?
Thanks,
Antonio

Antonio Salazar Cardozo

unread,
Oct 12, 2016, 8:34:48 AM10/12/16
to Lift
Tried pulling this project down to investigate, but it uses maven and
an incredibly outdated version of lift-mapper, so I didn't have time to
really get it running :/

If there's a version that uses sbt and/or a more recent version of Lift,
I can have a closer look.
Thanks,
Antonio

Jonathan

unread,
Oct 12, 2016, 10:07:42 AM10/12/16
to Lift
Hi, thanks for your responds.

I cloned the liquidizer project on a ubuntu OS in a virtual machine, changed the used java jdk via the command 'export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-amd64"  ' to version 7 (because maven reported errors with JDK version 8, but worked fine with JDK version 7) and ran "mvn jetty:run". That worked for me. Maven should download the right dependencies (e.g. the correct version of lift-mapper) automatically, shouldn't it?

Unfortunately I cannot provide a liquidizer version that uses sbt and/or a more recent version of Lift because I am unfamiliar with Lift.

Jonathan

unread,
Oct 12, 2016, 10:10:31 AM10/12/16
to Lift
The users thing lists the users of the database administration (for h2 the standard user is "SA"), not the users of the web application.
empty_h2_database_02.png

Tobias Hammerschmidt

unread,
Oct 12, 2016, 10:22:17 AM10/12/16
to Lift
Make sure to only use the base name of the database when connecting - h2 will automatically append h2.db  so if you use parts of this suffix during connection you'll end up using another db.

Jonathan

unread,
Oct 12, 2016, 10:50:50 AM10/12/16
to Lift
I tried the following JDBC URLs:

jdbc:h2:tcp://localhost/~/windowsHome/workingDir/Elice/lift_proto.db.h2.db;AUTO_SERVER=TRUE
and
jdbc:h2:tcp://localhost/~/windowsHome/workingDir/Elice/lift_proto.db;AUTO_SERVER=TRUE

which result in no difference. In either case the h2 console application seems to connect to a (new) empty database.

Diego Medina

unread,
Oct 12, 2016, 11:06:19 AM10/12/16
to Lift
I think the tcp prefix isn't doing what you expect, just to throw another way of connecting to your db, see this post I wrote a while ago


you would then access the h2 UI through the web server that is also hosting your lift app and if memory serves well, you just need to use the right db name, see screenshot on the post

Hope it helps.

Diego


--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala Consultant
di...@fmpwizard.com
http://blog.fmpwizard.com/
Message has been deleted

Jonathan

unread,
Oct 13, 2016, 5:56:10 AM10/13/16
to Lift
Hello Diego,

Thanks for your post! Your code snippets in the blog post helped me to make a successful connection!

For the ones who had the same problem as me: The following jdbc URL worked for me while being in server mode

 jdbc:h2:tcp://localhost/~/windowsHome/workingDir/Elice/lift_proto.db;AUTO_SERVER=TRUE using an empty user name and an empty password

I want to use Diegos solution for accessing the database. But it is not possible to connect to the database this way from outside (I have the web application running on a ubuntu guest in a virtual machine and try to connect to the localhost of the guest through the web browser on the host machine. This is possible via port forwarding in the virtual machine; the port 9999 on the host machine points to port 8080 in the guest machine). I get the message "Sorry, remote connections ('webAllowOthers') are disabled on this server." when I type "localhost:9999/console" in the web browser.

I have the following questions:
  • How can I make the h2 console application available for the outside world?
  • How can I set up a proper username and password so that only authorized actors (my web application and I) can get access to the database? I do not see any instructions in the Lift Cookbook to achieve this.

Thanks in advance,

Jonathan



On Wednesday, 12 October 2016 17:06:19 UTC+2, fmpwizard wrote:
I think the tcp prefix isn't doing what you expect, just to throw another way of connecting to your db, see this post I wrote a while ago


you would then access the h2 UI through the web server that is also hosting your lift app and if memory serves well, you just need to use the right db name, see screenshot on the post

Hope it helps.

Diego

On Wed, Oct 12, 2016 at 10:50 AM, Jonathan <jcse...@gmail.com> wrote:
I tried the following JDBC URLs:

jdbc:h2:tcp://localhost/~/windowsHome/workingDir/Elice/lift_proto.db.h2.db;AUTO_SERVER=TRUE
and
jdbc:h2:tcp://localhost/~/windowsHome/workingDir/Elice/lift_proto.db;AUTO_SERVER=TRUE

which result in no difference. In either case the h2 console application seems to connect to a (new) empty database.


On Wednesday, 12 October 2016 16:22:17 UTC+2, Tobias Hammerschmidt wrote:
Make sure to only use the base name of the database when connecting - h2 will automatically append h2.db  so if you use parts of this suffix during connection you'll end up using another db.

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages