You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by Apache Wiki <wi...@apache.org> on 2009/06/30 15:40:47 UTC

[Db-derby Wiki] Update of "DerbyAndPerlWithDBDJDBC" by BerntJohnsen

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Db-derby Wiki" for change notification.

The following page has been changed by BerntJohnsen:
http://wiki.apache.org/db-derby/DerbyAndPerlWithDBDJDBC

The comment on the change is:
  

New page:
= Derby and Perl with DBD::JDBC =

It is possible to use Perl to access Derby through DBD::JDBC. DBD::JDBC is a DBD server in pure Java which acts as a proxy server for any JDBC compliant database. This fits neatly with embedded Derby. You then get just one database server to worry about.


== What you need ==

 * You need to install DBD::JDBC from CPAN
 * You need the dbd_jdbc.jar file from the DBD::JDBC bundle
 * You need the log4j jar file from Apache
 * ... and of course Derby...


== How to do it ==

Start the dbd_jdbc server like this:

{{{
java -Djdbc.drivers=org.apache.derby.EmbeddedDriver \
     -Ddbd.port=12345 \
     -classpath db-derby-10.5.1.1-lib/lib/derby.jar:DBD-JDBC-0.71/dbd_jdbc.jar:apache-log4j-1.2.15/log4j-1.2.15.jar \
     com.vizdom.dbd.jdbc.Server
}}}

And then just run your perl program:
{{{
use DBD::JDBC;

$url = "jdbc:derby:dbtest;create=true";
## Since space, ';' and '=' is used in DBD dsn, 
## we need to encode them in the url:
$url =~ s/([=;])/uc sprintf("%%%02x",ord($1))/eg;
$dsn = "dbi:JDBC:hostname=localhost:12345;url=$url";

$dbh = DBI->connect($dsn, undef, undef, undef);

print "Derby system tables\n--------------------------\n";
$sth = $dbh->prepare("select tablename from SYS.SYSTABLES");
$sth->execute();
while (my ($i) = $sth->fetchrow_array) {
    print "Found: $i\n";
}
}}}

Which will produce the following output:
{{{
Derby system tables
--------------------------
Found: SYSALIASES
Found: SYSCHECKS
Found: SYSCOLPERMS
Found: SYSCOLUMNS
Found: SYSCONGLOMERATES
Found: SYSCONSTRAINTS
Found: SYSDEPENDS
Found: SYSDUMMY1
Found: SYSFILES
Found: SYSFOREIGNKEYS
Found: SYSKEYS
Found: SYSROLES
Found: SYSROUTINEPERMS
Found: SYSSCHEMAS
Found: SYSSTATEMENTS
Found: SYSSTATISTICS
Found: SYSTABLEPERMS
Found: SYSTABLES
Found: SYSTRIGGERS
Found: SYSVIEWS
}}}

== Links ==

 * http://search.cpan.org/~vizdom/DBD-JDBC-0.71/JDBC.pod
 * http://db.apache.org/derby/
 * http://logging.apache.org/log4j/

Re: [Db-derby Wiki] Update of "DerbyAndPerlWithDBDJDBC" by BerntJohnsen

Posted by "Dag H. Wanvik" <Da...@Sun.COM>.
Apache Wiki <wi...@apache.org> writes:

> = Derby and Perl with DBD::JDBC =

Thanks for this page, Bernt! This may prove really useful for some
users out there! :)