H2(embedded mode) and Netbeans IDE

1,676 views
Skip to first unread message

Paluee

unread,
Jan 13, 2010, 4:59:22 PM1/13/10
to H2 Database
Hi there,

I wish to do database design with H2 in Netbeans IDE , but in embedded
mode.
I have done database design with Netbeans with MySQL, but that was
running as a server and all the table structures + data already
existed and Netbeans just connected to the database that was fully up
and running.

I have done embedded mode with H2 using regular JDBC. But, in embedded
mode the
database structures and data don't exist untiil runtime.

SO this is my dilemma. How can Netbeans connect to a database before
it even exists?

I found a previous link in this forum, but at the very end no one
answered the similar questions to mine:

http://groups.google.com/group/h2-database/browse_thread/thread/7d212f32b8205325/a10349b8c39a07dc?hl=en&lnk=gst&q=H2+and+netbeans#a10349b8c39a07dc

This forum post has the title:
"Visual data-modeling tools for H2"

Any help will be greatly appreciated!

Paluee


JavaGuy

unread,
Jan 14, 2010, 1:51:01 AM1/14/10
to H2 Database
Hi Pauluee,

The link you provided answers the NetBeans questions perfectly.
The message by Ewald on Mar 30 2009 explains how to load the H2 Driver
in NetBeans and connect to your database.
The very next message explains a quirk in NetBeans and an Embedded H2
connection (it doesn't get closed properly).

So,
1. Load the H2 driver in NetBeans (Go to Services Tab >> Databases >>
Right click Drivers and select New Driver)
2. Right click your newly created driver and select Connect Using.
Fill in your username, password and the URL. (if the OK button isn't
enabled, just select another field first and it will become enabled)


"But, in embedded mode the database structures and data don't exist
untiil runtime. "

This isn't correct. If the Database doesn't exist, an empty one will
be created for you (regardless of wheather it's an embedded or tcp
connection). You can now use SQL statements from within NetBeans to
create tables, do queries etc. by right clicking on
Databases >> YourDBNode >> PUBLIC >> Tables and selecting Execute
Command, or just select Create Table to create it graphically.


If your URL is for a local connection, remember that you can't connect
to the same database from another process concurrently.
Since NetBeans doesn't close the local connection properly, you won't
be able to connect from an application you write within NetBeans if
you already made a connection to it from the Services Tab. This
connection only really gets closed if you close NetBeans.

A good option is to start the H2 server first by double clicking the
h2.jar file and connect to it using a tcp connection (jdbc:h2:tcp://
localhost//the/path/to/the/db). This way you can have a connection
open in NetBeans, as well as run an app you wrote that connects to the
same db.
When your app is finished, change the url in the application to
embedded mode and test it again.

Hope this helps

MicheleDG

unread,
Jan 14, 2010, 3:28:29 AM1/14/10
to H2 Database
Hi Paulee,
JavaGui already gave you a clear explain on working on Netbeans with
H2 in embedded mode.
I can just add a little hint here, useful if you're just starting
using Java and Netbeans.
If you're creating a new project using Netbeans CRUD template you
would probably like to have a "master" database table and a "details
table" showing in the same GUI.
To let Netbeans do the work smoothly your H2 database needs to be
properly built, with foreign keys already defined.
If you don't define foreing keys Netbeans cannot automatically bind
two tables and you'll have just a single table shown on your CRUD GUI
project.
Anyway, if you're an experienced user you won't have any kind of
problem.
Best regards !

Michele

Reply all
Reply to author
Forward
0 new messages