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:
This forum post has the title:
"Visual data-modeling tools for H2"
Any help will be greatly appreciated!
Paluee
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
Michele