How to Connect to a hsqldb DB with the Eclipse WTP Database Explorer…

While in the Spring class I’m taking, this past Saturday, the question came up, “So how can you connect to a hsqldb db with the Eclipse WTP Database Explorer?” It’s not very obvious because there is no entry for hsqldb in the Database Manager list from the New Connection screen. I spent a few minutes Googling for some answers and didn’t see anything in the “first 10” so I decided to just “play around” and figure it out. Anyhow, it ended up being fairly easy. You just need to know what values go where in the setup process. Read on for the exciting instructions.

First, you need to get and install the Eclipse Web Tools Platform (WTP from now on). Then from either the Java Perspective or the J2EE Perspective click on Window -> Show View -> Other. Click the plus next to Data to expand the folder and select Database Explorer (show view example). Now the Database Explorer should be active on your screen. Right-click on Connections and select New Connection (new connection screen).

Here is where most people get nervous and think they can’t use hsqldb with Eclipse WTP. Wrong! Just leave DB2 selected and make sure the Other shows up in the JDBC Driver drop-down. Next fill in the appropriate values for your db in the Connection URL details section. For me, I had a database named loan, my JDBC driver class is org.hsqldb.jdbcDriver, for class location I browsed to the location of my hsqldb.jar file, and I used jdbc:hsqldb:hsql://localhost/loan for my Connection URL. The last step is setting your userid and password in the User Information section (finished New Connection Screen). Once you’ve done that you can hit Finish and you should be good-to-go (connected to hsqldb view). I don’t like that it says “DB2…” next to my hsqldb connection entry, but it works. I’m gonna spend some time trying to change that in the next few days.

This entry isn’t a tutorial on how to use the Database Explorer view but to get you started I’ll give a couple tips. First, right-click on your newly created db in the Database Explorer view and select Open SQL Scrapbook. Select the project that the sql file will belong to (I have one for each project that I work on and I just don’t sync it with CVS), give it a name (the editor will add an extension so just use something like sql_statements), and then click finish. You’ll now have a “sql scrapbook page” that you can write sql statements in. The last thing I will say is that you can write whatever you want in the scrapbook page. To execute a sql statement simply highlight the statement and right-click and select Run SQL. A Data Output view will open, right next to your Database Explorer with the results of your statement (results of running a sql query).

I hope that helps. I know one person that should find these instructions useful. 😉 Let me know if anything here wasn’t clear.

This Post Has 3 Comments

  1. Louis A J

    Can’t connect to DB2 using Eclipse Database Explorer

    I’m posting this because I was looking for the answer and ended up stumbling across it the old fashioned way (trial and error). This page was near the top of my google search results when looking for an answer.

    I couldn’t connect to DB2 using the Database Explorer. I had supplied the driver jar, but it kept complaining about needing the license jar. The solution is pretty simple:
    In the ‘Class Location:’ prompt simply supply the path to both jar files, separated by a semicolon. I did this by selecting both files in the browse dialogue box and clicking [ok].

  2. senthil

    thanks erik,
    its nice . how about hsqldb plugin for eclipse (which is developed by ibm developerworks). i tried that but i could not get. so i am using your approach.
    but i want to know about hsqldb plugin

  3. jan_bar

    Thanks for you article. I did the same as you wrote, but I used Generic JDBC as the database manager. It didn’t worked well, with DB2 it works better.

Leave a Reply