aspose file tools*
The moose likes JDBC and the fly likes Java DB/Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Java DB/Eclipse" Watch "Java DB/Eclipse" New topic
Author

Java DB/Eclipse

George Willis
Ranch Hand

Joined: Jun 13, 2013
Posts: 37
Two concerns that I am hoping to get help with my 1st foray into Java & databases:

1) I am looking at adding DTP to my Eclipse IDE for Java Developers. I found the download for DTP 1.11.0 at eclipse.org. The downloaded zip produced a 'features' folder containing 'datatools', a 'plugins' folder with a bunch of '.jar's', an 'epl-v10.html' (public license), and a 'notice.html' (user agreement). Googling further(1 hit), it seems that I can now "merge" (ehem, does that mean copy?) these into my existing Eclipse 'features' amd 'plugins' folders; and I suppose that I can just forget about 2 html files overwriting the existing ones. Can anyone confirm that this is the correct way to accomplish this? I would have hoped for perhaps a setup app or at least a ReadMe file for further instructions, but no. I just don't want to screw up an Eclipse is currently working just fine.

It appears that an alternative (preferred?) method was to go to Eclipse Help-->Install New Software...-->--All Available Sites--, and find it there. Under the result, 'Datbase Development', there are 2 items:
1) Data Tools Platform Enablement extender SDK, v1.10.2.etc....
2) Data Tools Platform Extender SDK, v1.10.2.etc...

...I'm guessing I would need both of these from the few Google search hits that were returned. But, why isn't v1.11 available even though my Eclipse appears to meet the requirements?:
Eclipse 3.7.2, tested with 4.3 - I have 4.2
EMF 2.7.2, tested with 2.9 - I have version 2.8
GEF 3.7.2, tested with 3.9 - I have 3.9
JDK 1.6 - I have 1.7

It looks like the safe bet is just go with what Eclipse offers me. But, what about 1.11?

After I have this loaded will I be able to access existing databases created programatically? I'm interested in viewing them if I can.

2)It seems to me that a resonable place to start learning about Java's DB capabilities is simply what Java provides by default, Java DB. And, it appears that Java DB might be the ticket for what I am looking for in my learning desktop app. What I'm doing is reading a collection of text file reports and extracting data that I need: device names, device status, users, time stamps. All the data thus far is being returned to the Eclipse Console. I intend to have 'The User' click a button to create a database. And then click another button to update the database. After that, The User will be able to report on device use over time, number of devices used, etc.. There doesn't seem to be alot of detail about Derby aside from the derby/docs on the Apache site. Java For Dummy's and Core Java Vol2 have code hints that should be easy to plug into my app. But, I'm hoping to get some answers to a couple of questions that I am looking into:
Can a blank database be created(table without records)?
Does Java DB persist after the table/records have been entered?
Any thoughts on using a Primary Key for a table when that data available doesn't really have anything unique(like the typical Account examples found in books)?

Thanks in advance!

Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 513
    
    6
Regarding #1:
I've not used DTP, so I won't comment specifically on installation steps. In general though, I prefer the versions from official repositories, rather than doing something manually. That said, getting plugin versions wrong in eclipse has never wrecked my eclipse. At worst, the plugin won't work. However, if you still want to be absolutely sure, you can always make a copy of your complete eclipse directory, and experiment on the copy. That way, your original installation will still be safe. It's perfectly ok to have multiple eclipse installations in the same system; there's no registry or anything else to make them trip over one another.

Regarding #2:
Yes, a blank database can be created without any tables in any DB, including JavaDB. In the JDBC URL, you just have to suffix a ";create=true". Examples connection URLs are here.

Does Java DB persist after the table/records have been entered?

There are 4 ways to which JavaDB can be used:
1) As an embedded in-memory database:
In this mode, data is stored only in memory and not persisted to file system.
The memory belongs to the same java process as your learning application.
There are ways to persist this kind of memory db if you change your mind later on. Their dev guide explains how.

2) As an embedded persisted database:
All data changes are persisted to file system.
The javadb engine is loaded in the same process as your learning application. The host application is responsible for proper startup and shutdown of database engine.
Note: Such a database can be opened by only 1 process at a time. This is an inconvenience for you to use DTP to visualize the data, because DTP plugin hosted in eclipse is a separate
process from your learning app.

3) As a client server in-memory database:
Here too, data is stored only in memory and not persisted to file system.
In this mode, JavaDB engine is hosted in a dedicated server process, and not in your learning app process.
The data in memory belongs to the server process, unlike in embedded in-memory mode .

4) As a client server persisted database:
All data changes are persisted to file system.
This is similar to the typical mode that other common databases like mysql use.
The JavaDB engine is hosted in a dedicated server process, and not in your learning app process. The server process is responsible for proper startup and shutdown of javadb engine.

Summary:
Since you wish to use a tool like DTP to visualize data, possibly doing so even while your application is running, you should run JavaDB in mode 4) above.
In embedded modes, you'll have to first close your application every time you want to examine the DB using DTP.

Any thoughts on using a Primary Key for a table when that data available doesn't really have anything unique(like the typical Account examples found in books)?

I typically use a unique identifier generated by the DB. The term for that is surrogate key.
Some DB/DBA purists don't like it because it increases storage space, but I find it very convenient and use it even if the queries I have in mind at that point of time in the development cycle don't require it.

Clean shutdown tip: One tip on using JavaDB in embedded mode is your application is responsible for cleanly shutting it down when it's closing. The way to do that is to open a special connection that shuts it down (yes, you read it right - you have to open a connection to shut it down!). The line below cleanly shuts it down and even throws an SQLException which is not really an error but an indication of successful shutdown because it's message is "Derby system shutdown". Very odd, but there you go!
George Willis
Ranch Hand

Joined: Jun 13, 2013
Posts: 37
Belated thank you. I was in the process of reading K. A Mughal's Java SCJP book (a bear of a read for a noob) and was sidetracked on a couple of other things.
 
Consider Paul's rocket mass heater.
 
subject: Java DB/Eclipse