You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Ricardo Seromenho <a2...@ualg.pt> on 2008/03/27 03:38:22 UTC
How to make a simple app with a Java Db embedded ?
Hello,
I am using NetBeans IDE 6.0 and having some difficult to make a simple
app with a embedded database.
What I am able to do is an application with a database but not ebedded...
So, what I need to do to embedde that database on the application?
Thank you
--
========================================================
Ricardo José da Silva Seromenho
Aluno 23842 Universidade do Algarve, Campus de Gambelas
e-mail: a23842@ualg.pt
web: http://www.deei.fct.ualg.pt/~a23842/
Re: How to make a simple app with a Java Db embedded ?
Posted by Donald McLean <dm...@gmail.com>.
Actually, just having an embedded database is pretty simple. If you look at
the source for the simple class DatabaseManager (
http://wiki.apache.org/db-derby/DatabaseManagerSource) it lays it all out
for you but in essence you need to:
1. load the driver (static block at the end)
2. create a proper URL for the database (function creatURL)
3. connect to the database (function connectToDatabase)
Donald
On Wed, Mar 26, 2008 at 10:53 PM, Ricardo Seromenho <a2...@ualg.pt> wrote:
> Hello,
> I am using NetBeans IDE 6.0 and having some difficult to make a simple
> app with a embedded database.
>
> What I am able to do is an application with a database but not ebedded...
>
> So, what I need to do to embedde that database on the application?
>
Re: Question about Embedded Derby
Posted by Daniel Noll <da...@nuix.com>.
On Friday 28 March 2008 13:21:52 Kai Ponte wrote:
> First you might want to stop top posting. It makes things hard to read.
> Second you might want to upgrade from Wintendo to a real OS.
Hey now, don't say things like this, it's not fair to Nintendo.
Daniel
Re: Question about Embedded Derby
Posted by John Embretsen <Jo...@Sun.COM>.
Ricardo Seromenho wrote:
> Sory about top posting...
> I think it's very easy to read...but you prefer mid posting or down
> posying or whatever posting...
> And when you say to upgrade to a real OS, I am not interested in discuss
> wath is a real OS or what is the best OS, bu the application that I want
> to make is one that works in any OS.
> One that, if you put it on a pen device it work in Wintendo and in your
> real OS.
>
> And to terminate, sory to this ML if this wasn't the proper place to put
> my questions.
First of all: It is usually safe and perfectly OK to ignore comments about more
or less religious topics such as which OS is best or worst.
Second: Sure, this mailing list was the proper place for your questions.
Although you have posted a few different questions in the same thread, and some
might be related to NetBeans, I believe you have good chances of getting useful
answers on this list - as long as it is directly related to Derby.
In your case, you should be aware that
- The Derby Developers Guide [1] says that: "The path separator in the
connection URL is / (forward slash), as in the standard file:// URL protocol."
However, using double or even single backslashes may work in some cases as well
as well, though you should stick to the documentation. This is true even on Windows.
See also references I provided in the netbeans-users thread you referred to
earlier [3].
- There is a difference between relative and absolute paths in connection URLs
[2]. When using an embedded database (i.e., JDBC connection), the world is a bit
less complicated than client/server. Do some experiments to understand how it works.
- You need to define a "home", a place for your database. If you want to
bundle the database with your application, you could make sure it is always in
the same place relative to some resource, making it easier to determine the
correct URL.
If you have further problems, don't be afraid to ask.
--
John
[1]: http://db.apache.org/derby/docs/dev/devguide/cdevdvlp40350.html
[2]: http://wiki.apache.org/db-derby/DatabaseNamesRelativeAbsolute
[3]: http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#a15200685
Re: Question about Embedded Derby
Posted by Ricardo Seromenho <a2...@ualg.pt>.
Sory about top posting...
I think it's very easy to read...but you prefer mid posting or down
posying or whatever posting...
And when you say to upgrade to a real OS, I am not interested in discuss
wath is a real OS or what is the best OS, bu the application that I want
to make is one that works in any OS.
One that, if you put it on a pen device it work in Wintendo and in your
real OS.
And to terminate, sory to this ML if this wasn't the proper place to put
my questions.
Kai Ponte wrote:
> On Thursday 27 March 2008 05:06:22 pm Ricardo Seromenho wrote:
>
>> Ok,
>>
>
> First you might want to stop top posting. It makes things hard to read.
> Second you might want to upgrade from Wintendo to a real OS.
>
>
>
>> But the thing is: on Netbeans, when creting a new project (lets say that
>> I already have created the database)
>> I do the following:
>> Choose Project -> Java -> Java desktop Application -> NEXT.
>> And then I choose Database aplication.
>> On the next screen I need to choose the database. And I want it to be
>> embedded.
>>
>> What steps should I take ?
>> Thanks
>>
>
> Okay, I'd highly suggest taking this off the Derby mailing list and putting
> the question on the Netbeans mailing list. Lots of good folks there who can
> give you direct netbeans answers:
>
> http://www.netbeans.org/community/lists/top.html
>
> You want the nbusers@netbeans.org list.
>
> Now, to answer your question:
>
> In the drop down for database, choose "New Database Connection."
>
> You can then choose an embedded database and select the one you want.
>
>
--
========================================================
Ricardo José da Silva Seromenho
Aluno 23842 Universidade do Algarve, Campus de Gambelas
e-mail: a23842@ualg.pt
web: http://www.deei.fct.ualg.pt/~a23842/
Re: Question about Embedded Derby
Posted by Kai Ponte <ka...@perfectreign.com>.
On Thursday 27 March 2008 05:06:22 pm Ricardo Seromenho wrote:
> Ok,
First you might want to stop top posting. It makes things hard to read.
Second you might want to upgrade from Wintendo to a real OS.
> But the thing is: on Netbeans, when creting a new project (lets say that
> I already have created the database)
> I do the following:
> Choose Project -> Java -> Java desktop Application -> NEXT.
> And then I choose Database aplication.
> On the next screen I need to choose the database. And I want it to be
> embedded.
>
> What steps should I take ?
> Thanks
Okay, I'd highly suggest taking this off the Derby mailing list and putting
the question on the Netbeans mailing list. Lots of good folks there who can
give you direct netbeans answers:
http://www.netbeans.org/community/lists/top.html
You want the nbusers@netbeans.org list.
Now, to answer your question:
In the drop down for database, choose "New Database Connection."
You can then choose an embedded database and select the one you want.
--
kai
www.filesite.org || www.4thedadz.com || www.perfectreign.com
remember - a turn signal is a statement, not a request
Re: Question about Embedded Derby
Posted by Ricardo Seromenho <a2...@ualg.pt>.
Ok,
But the thing is: on Netbeans, when creting a new project (lets say that
I already have created the database)
I do the following:
Choose Project -> Java -> Java desktop Application -> NEXT.
And then I choose Database aplication.
On the next screen I need to choose the database. And I want it to be
embedded.
What steps should I take ?
Thanks
On NetBeans 6.0
Kai Ponte wrote:
> On Thursday 27 March 2008 12:34:50 pm bruehlicke wrote:
>
>> I let let user pick a directory (either via a property or via a file
>> selector) than I set the derby.system.home property programtically like
>>
>> System.setProperty("derby.system.home", dbLocation);
>>
>> The value of dbLocation when you print it is for ex. C:\Documents and
>> Settings\fred\xyz (that is the way you should set the value) but when you
>> use the debugger it will of course show up as C:\\Documents and
>> Settings\\fred\\xyz
>>
>> After this value is set I use the URL like jdbc:derby:myDB;create=true
>> and the database myDB is created under the given directory.
>>
>> Hope this helps
>> B-)
>>
>
> That would work out well.
>
> On my apps, I usually place the database - and various config files - in a
> folder under the user's home folder.
>
> I have line -
>
> File strHomeFolder = new File ( System.getProperty("user.home") + "/.MyApp");
>
>
> I then append a database folder under this for the database.
>
> In any case, when I'm downgrading to legacy operating systems that still use
> drive letters like Wintendo - I have one vista, one Xp and one win2K
> machine - I do the followng
>
> jdbc:derby:C:\Path\To\data
>
> HTH!
>
--
========================================================
Ricardo José da Silva Seromenho
Aluno 23842 Universidade do Algarve, Campus de Gambelas
e-mail: a23842@ualg.pt
web: http://www.deei.fct.ualg.pt/~a23842/
Re: Question about Embedded Derby
Posted by Kai Ponte <ka...@perfectreign.com>.
On Thursday 27 March 2008 12:34:50 pm bruehlicke wrote:
> I let let user pick a directory (either via a property or via a file
> selector) than I set the derby.system.home property programtically like
>
> System.setProperty("derby.system.home", dbLocation);
>
> The value of dbLocation when you print it is for ex. C:\Documents and
> Settings\fred\xyz (that is the way you should set the value) but when you
> use the debugger it will of course show up as C:\\Documents and
> Settings\\fred\\xyz
>
> After this value is set I use the URL like jdbc:derby:myDB;create=true
> and the database myDB is created under the given directory.
>
> Hope this helps
> B-)
That would work out well.
On my apps, I usually place the database - and various config files - in a
folder under the user's home folder.
I have line -
File strHomeFolder = new File ( System.getProperty("user.home") + "/.MyApp");
I then append a database folder under this for the database.
In any case, when I'm downgrading to legacy operating systems that still use
drive letters like Wintendo - I have one vista, one Xp and one win2K
machine - I do the followng
jdbc:derby:C:\Path\To\data
HTH!
--
kai
www.filesite.org || www.4thedadz.com || www.perfectreign.com
remember - a turn signal is a statement, not a request
Re: Question about Embedded Derby
Posted by bruehlicke <br...@gmail.com>.
I let let user pick a directory (either via a property or via a file
selector) than I set the derby.system.home property programtically like
System.setProperty("derby.system.home", dbLocation);
The value of dbLocation when you print it is for ex. C:\Documents and
Settings\fred\xyz (that is the way you should set the value) but when you
use the debugger it will of course show up as C:\\Documents and
Settings\\fred\\xyz
After this value is set I use the URL like jdbc:derby:myDB;create=true
and the database myDB is created under the given directory.
Hope this helps
B-)
On Thu, Mar 27, 2008 at 2:15 PM, Ricardo Seromenho <a2...@ualg.pt> wrote:
> PerfectReign has posted the message above and I am with the same problem.
>
> The question is:
> What should be the Database URL ?
> like this:
> C:\\SOMEWHERE\\
> or
> C\:\\SOMEWHERE\\
> or
> C:/SOMEWHERE/
>
> ?
>
> Thanks
>
>
>
> ----------------
>
>
> Question about Embedded Derby [image: Click to flag this post]
>
> by PerfectReign <http://www.nabble.com/user/UserProfile.jtp?user=123271>Jan 30, 2008; 09:33pm:: Rate this Message:
> <http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#><http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#><http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#><http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#><http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#><http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#>
> <http://www.nabble.com/Question-about-Embedded-Derby-td15192640.html#>-
> Use ratings to moderate (? <http://www.nabble.com/help/Answer.jtp?id=16>)
>
> I have successfully completed the "Building a *Java* Desktop Datbase
> Application" tutorial at:
> http://www.*netbeans*.org/kb/60/*java*/gui-*db*.html<http://www.netbeans.org/kb/60/java/gui-db.html>
>
> Very nice work!
>
>
> I am now trying to do the same thing only using an Embedded Derby
> database.
>
> I am able to create the database (using ij) and then connect to it.
> However, when I go to run the app, I get an error in my
> CarsAppView.*java* file.
>
> It is at this line (in grey):
>
> entityManager =
> *javax*.persistence.Persistence.createEntityManagerFactory("jdbc:derby:C:\projects\embeddedCar\CARSDBPU").createEntityManager();
>
>
>
> The error message states: "*illegal* *escape* *character*" at each of the
> three backslashes.
>
> Since this is non-editable, what can be done?
>
> --
> ========================================================
> Ricardo José da Silva Seromenho
> Aluno 23842 Universidade do Algarve, Campus de Gambelas
> e-mail: a23842@ualg.pt
> web: http://www.deei.fct.ualg.pt/~a23842/ <http://www.deei.fct.ualg.pt/%7Ea23842/>
>
>
Re: How to make a simple app with a Java Db embedded ?
Posted by Kai Ponte <ka...@perfectreign.com>.
On Wednesday 26 March 2008 07:53:48 pm Ricardo Seromenho wrote:
> Hello,
> I am using NetBeans IDE 6.0 and having some difficult to make a simple
> app with a embedded database.
>
> What I am able to do is an application with a database but not ebedded...
>
> So, what I need to do to embedde that database on the application?
>
Here's an example in Netbeans 5.0 which is a little different..
http://www.netbeans.org/kb/50/derby-demo.html
...and one in 6.0...
http://www.netbeans.org/kb/60/java/gui-db.html
..both of which use the Network database. The second example also uses
persistence, which I really don't like. (It causes too much complication.)
To use embedded, you need to have your database setup and the path known.
What I do to connect - when I'm not using persistence - is the following:
String databasename = <path to database>/database_folder
public String framework = "embedded";
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
Note that I'm using the EmbeddedDriver.
You also need the derby.jar file somewhere in your classpath or accessable as
a library in your project.
public String protocol = "jdbc:derby:";
public Connection conn = null;
then in a try/catch block I do the following...
Class.forName(driver).newInstance();
//Load the appropriate driver
Properties props = new Properties();
props.put("user", "dbuser");
props.put("password", "dbuser");
conn = DriverManager.getConnection(protocol + databasename,
props);
That's pretty much it.
--
kai
www.filesite.org || www.4thedadz.com || www.perfectreign.com
remember - a turn signal is a statement, not a request
Re: How to make a simple app with a Java Db embedded ?
Posted by bruehlicke <br...@gmail.com>.
I have a successful NetBeans RCP app running with Derby embedded.
1) Create a Library Wrapper module with derby jar
2) Make sure you create your db with org.apache.derby.jdbc.EmbeddedDriver
3) I did set the system.derby.home to a local project dir
What do you mean with " What I am able to do is an application with a
database but not ebedded..." ? Of course even if you use the Embedded Driver
will Derby put files on your disk for persistence - maybe you can elaborate
a little on this.
B-)
On Wed, Mar 26, 2008 at 9:53 PM, Ricardo Seromenho <a2...@ualg.pt> wrote:
> Hello,
> I am using NetBeans IDE 6.0 and having some difficult to make a simple
> app with a embedded database.
>
> What I am able to do is an application with a database but not ebedded...
>
> So, what I need to do to embedde that database on the application?
>
> Thank you
>
> --
> ========================================================
> Ricardo José da Silva Seromenho
> Aluno 23842 Universidade do Algarve, Campus de Gambelas
> e-mail: a23842@ualg.pt
> web: http://www.deei.fct.ualg.pt/~a23842/<http://www.deei.fct.ualg.pt/%7Ea23842/>
>
>
Re: How to make a simple app with a Java Db embedded ?
Posted by Ricardo Seromenho <a2...@ualg.pt>.
Hello,
I am using NetBeans IDE 6.0 and having some difficult to make a simple
app with a embedded database.
What I am able to do is an application with a database but not ebedded...
So, what I need to do to embedde that database on the application?
Thank you
--
========================================================
Ricardo José da Silva Seromenho
Aluno 23842 Universidade do Algarve, Campus de Gambelas
e-mail: a23842@ualg.pt
web: http://www.deei.fct.ualg.pt/~a23842/