db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kai Ponte <...@perfectreign.com>
Subject Re: How to make a simple app with a Java Db embedded ?
Date Thu, 27 Mar 2008 04:28:55 GMT
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

Mime
View raw message