Keeping it Small and Simple

2008.03.11

Oh Derby! Dumb, dumb, dumb Derby.

Filed under: Java Programming — Tags: , , , , , , , , , , — Lorenzo E. Danielsson @ 16:35

I was playing around with Apache Derby today. You know, that database server that started life as Cloudscape, became Derby and is now included in the JDK. Yeah, that one. For Debian (Sid) users, it is available via a aptitude install sun-java6-javadb.

I had a little file I was trying to import, called cartoons.sql.

 1 /*
 2  * Here there be ‘toons!
 3  */
 4
 5 CONNECT ‘jdbc:derby:toonsdb;create=true’;
 6
 7 CREATE TABLE cartoons(
 8     cartoon_id INT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
 9     cartoon VARCHAR(255) NOT NULL,
10     UNIQUE(cartoon)
11 );
12
13 INSERT INTO cartoons(cartoon) VALUES(‘Bugs Bunny’);
14 INSERT INTO cartoons(cartoon) VALUES(‘Daffy Duck’);
15 INSERT INTO cartoons(cartoon) VALUES(‘Tom the Cat’);
16 INSERT INTO cartoons(cartoon) VALUES(‘Jerry Mouse’);

So, I tried to import:

% java -cp /usr/lib/jvm/java-6-sun/db/lib/derby.jar:/usr/lib/jvm/java-6-sun/db/lib/derbytools.jar:. org.apache.derby.tools.ij  IJ ERROR: Unable to establish connection
ij> IJ ERROR: Unable to establish connection
ij>

Hm, weird. I started ij tried running all the commands manually and that worked fine. Then I found out that could call ij with the name of the file directly (that is without the redirection). This would echo all the commands.

% java -cp /usr/lib/jvm/java-6-sun/db/lib/derby.jar:/usr/lib/jvm/java-6-sun/db/lib/derbytools.jar:. org.apache.derby.tools.ij cartoons.sql                   
ij version 10.3
ij> /*
 * Here there be 'toons!
 */

CONNECT 'jdbc:derby:toonsdb;
IJ ERROR: Unable to establish connection
ij> create=true';

CREATE TABLE cartoons(
    cartoon_id INT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    cartoon VARCHAR(255) NOT NULL,
    UNIQUE(cartoon)
);

INSERT INTO cartoons(cartoon) VALUES('Bugs Bunny');
INSERT INTO cartoons(cartoon) VALUES('Daffy Duck');
INSERT INTO cartoons(cartoon) VALUES('Tom the Cat');
INSERT INTO cartoons(cartoon) VALUES('Jerry Mouse');
;
IJ ERROR: Unable to establish connection
ij>

Something is not right. I thought the comment should be discarded? So why do I see it in the output above? It doesn’t give any errors per se, but its presence there is disturbing. What happens if I remove the comment?

% java -cp /usr/lib/jvm/java-6-sun/db/lib/derby.jar:/usr/lib/jvm/java-6-sun/db/lib/derbytools.jar:. org.apache.derby.tools.ij cartoons.sql
ij version 10.3
ij> CONNECT 'jdbc:derby:toonsdb;create=true';
ij> CREATE TABLE cartoons(
    cartoon_id INT NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    cartoon VARCHAR(255) NOT NULL,
    UNIQUE(cartoon)
);
0 rows inserted/updated/deleted
ij> INSERT INTO cartoons(cartoon) VALUES('Bugs Bunny');
1 row inserted/updated/deleted
ij> INSERT INTO cartoons(cartoon) VALUES('Daffy Duck');
1 row inserted/updated/deleted
ij> INSERT INTO cartoons(cartoon) VALUES('Tom the Cat');
1 row inserted/updated/deleted
ij> INSERT INTO cartoons(cartoon) VALUES('Jerry Mouse');
1 row inserted/updated/deleted
ij>

Go figure! The comment is not being parsed, but does not end in a ; so it causes errors when I try to CONNECT. How fucking stupid is that?

For those who want an embeddable database written in Java, look at HSQLDB.

Advertisements

1 Comment »

  1. Free online programming tutorials resources and guide.

    Comment by Programming Tutorial — 2008.05.16 @ 11:34


RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: