This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Glassfish and the fly likes Netbeans database sample and Glassfish database sample Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Glassfish
Bookmark "Netbeans database sample and Glassfish database sample" Watch "Netbeans database sample and Glassfish database sample" New topic
Author

Netbeans database sample and Glassfish database sample

Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
I've installed Netbeans 7.1 IDE with the option to install Glassfish 3.1.1 as well.

So under netbeans I've written a JavaEE web app which writes to database jdbc/sample...and it does....under C:\Documents and Settings\David\.netbeans-derby\ is a folder 'sample'

However it is necessary to copy this folder to D:\Glassfish3\javadb\bin\ in order for glassfish running completely indepent of netbeans to use the sample db.

in short : Netbeans creates, reads and writes a db and it shows up in C:\Documents and Settings\David\.netbeans-derby\
Glassfish reads and writes a db and sees it only in D:\Glassfish3\javadb\bin\

How can I get these two guys to agree on a common place to park the sample database folder??
Dave Elwood
Ranch Hand

Joined: Dec 27, 2002
Posts: 84
I've found that strange things must be done to make this work.

In Netbeans under the Services tab, you right click on JavaDB and define where the databases are to be sought.

I put in D:\Glassfish3\glassfish\databases -

Before Netbeans does anything with any database, glassfish and then the database server must be turned on and when you turn them on the current directory must be somewhere other than D:\Glassfish3\glassfish\bin where asadmin.bat lies. To turn on glassfish and then the database server I made a batch file with the path to asadmin.bat written out fully :



putting the current directory far away from D:\Glassfish3\glassfish\bin is necessary otherwise the databases will originate in that directory.
putting the current directory on E:\ causes the database creation directory to be D:\Glassfish3\glassfish\databases - don't ask me why.

possibly during previous muck-ups the databases were created in the D:\Glassfish3\glassfish\bin folder and along
with that, a derby.log file and a derby.properties file. And then in the future, some process was looking for a neat place to
create the database files and since D:\Glassfish3\glassfish\bin is on PATH it looked there, saw derby.log and derby.properties
and said "this is the place".

So I wipe away ALL derby.log and derby.properties files.

With both servers up and running I go to the admin console

A. in Resources / JDBC / JDBC connection pools / SamplePool
Under the third tab is 'further properties'
here : URL = jdbc:derby://localhost:1527/newDBName
databaseName=newDBName
connectionAttributes=;create=true
Save should bring up a green ok

B. then in Resources / JDBC / JDBC Resources
add a new resource jdbc/newDBName
OK should not bring up any message

At this moment a new database folder newDBName appears under the databases folder, if not then
you were in the wrong seat when the plane crashed. Turn off both servers and turn then on again
and make sure that when turning on the database server the current dir is not where the glassfish\bin directory is.

So the new directory in glassfish\databases\newDBName is there.

So now turn both servers off.

Run Netbeans and write the Entity Bean app or modify an existing Entity Bean app (javaee6).
In persistence.xml is the name of the database. change the value to jdbc/newDBName and compile it.
Run it and Netbeans will turn on glassfish and the database server for you and do its job.

Then turn off Netbeans and turn glassfish and the database server on again for normal mortal use.
then localhost:8080/entitybeanapp. should do the job too.

Hope this helps somebody.
 
 
subject: Netbeans database sample and Glassfish database sample
 
Similar Threads
Path setting for Glassfish Installation
SQLSyntaxErrorException: Attempt to modify an identity column 'ID'
EJB, JSPs and JDBCs
Caused by: javax.naming.NamingException
Netbeans Community Development