A Techno Blog, mainly about Java

Derby Again

I have used derby a while back. Several years later, I wanted to get it installed again on my machine.

In short, Derby is the Java Database that IBM contributed to the open source community. It was known then as cloudscape.

I start off by getting the bin download from the derby database

create DERBY_HOME environment variable : C:\JAVA\derby10\db-derby-\
Make sure I have my JAVA_HOME environment variable properly set
add to the PATH: C:\JAVA\derby10\db-derby-\bin\

from the command line:



ij is the derby sql client command line

ij>connect ‘jdbc:derby://localhost:1527/mydb;



C:\JAVA\derby10\db-derby-\demo\programs\simple>set CLASSPATH=.;%DERB


C:\JAVA\derby10\db-derby-\demo\programs\simple>java org.apache.derby
.tools.sysinfo -cp embedded SimpleApp.class

Derby embedded engine library (derby.jar)

user-specified class (SimpleApp)

SUCCESS: All Derby related classes found in class path.

get ibm jars for derby
C:\JAVA\derby10\db-derby-\demo\programs\simple>set CLASSPATH=.;%DERB

C:\JAVA\derby10\db-derby-\demo\programs\simple>java SimpleApp jccjdb
SimpleApp starting in jccjdbc mode.
Loaded the appropriate driver.
Connected to and created database derbyDB
Created table derbyDB
Inserted 1956 Webster
Inserted 1910 Union
Updated 1956 Webster to 180 Grand
Updated 180 Grand to 300 Lakeshore
Verified the rows
Dropped table derbyDB
Closed result set and statement
Committed transaction and closed connection
SimpleApp finished

/* the default framework is embedded*/
public String framework = “embedded”;
public String driver = “org.apache.derby.jdbc.EmbeddedDriver”;
public String protocol = “jdbc:derby:”;

public static void main(String[] args)
new SimpleApp().go(args);

void go(String[] args)
/* parse the arguments to determine which framework is desired*/

System.out.println(“SimpleApp starting in ” + framework + ” mode.”);

The driver is installed by loading its class.
In an embedded environment, this will start up Derby, since it is not already running.
System.out.println(“Loaded the appropriate driver.”);

Connection conn = null;
Properties props = new Properties();
props.put(“user”, “user1”);
props.put(“password”, “user1”);

The connection specifies create=true to cause
the database to be created. To remove the database,
remove the directory derbyDB and its contents.
The directory derbyDB will be created under
the directory that the system property
derby.system.home points to, or the current
directory if derby.system.home is not set.
conn = DriverManager.getConnection(protocol +
“derbyDB;create=true”, props);

System.out.println(“Connected to and created database derbyDB”);


Creating a statement lets us issue commands against
the connection.
Statement s = conn.createStatement();

We create a table, add a few rows, and update one.

private void parseArguments(String[] args)
int length = args.length;

for (int index = 0; index < length; index++)
if (args[index].equalsIgnoreCase(“jccjdbcclient”))
framework = “jccjdbc”;
driver = “”;
protocol = “jdbc:derby:net://localhost:1527/”;
if (args[index].equalsIgnoreCase(“derbyclient”))
framework = “derbyclient”;
driver = “org.apache.derby.jdbc.ClientDriver”;
protocol = “jdbc:derby://localhost:1527/”;

July 5, 2008 - Posted by | SW Tools

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: