jainprithviraj has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am getting below error while connecting to Derby DB from my perl script. I could connect to Derby BY without using my script.

[root@prithvi bin]# perl tmp.pl DBI connect('hostname=localhost;port=1527;url=jdbc:derby:mydb%3Bsecuri +tyMechanism%3D8','myuser',...) failed: I/O Error 001bd00200010015124 +c0006114900080006000c00000005114a03 at tmp.pl line 9 Derby system tables -------------------------- Can't call method "prepare" on an undefined value at tmp.pl line 12. [root@prithvi bin]# [root@prithvi bin]# [root@prithvi bin]# cat tmp.pl use DBD::JDBC; $url = "jdbc:derby:mydb;securityMechanism=8"; ## 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;port=1527;url=$url"; $dbh = DBI->connect($dsn, "myuser", "mypassword"); 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"; } [root@prithvi bin]# [root@prithvi bin]# /opt/Java/jdk1.6.0_21/db/bin/ij ij version 10.5 ij> connect 'jdbc:derby://localhost:1527/mydb;securityMechanism=8;user +=myuser;password=mypassword'; ij>

Replies are listed 'Best First'.
Re: Error connecting to Derby DB
by Corion (Patriarch) on Apr 09, 2011 at 08:38 UTC

    You should read DBI and check for errors when connecting:

    $dbh = DBI->connect($dsn, "myuser", "mypassword", { RaiseError => 1, A +utoCommit => 0 }) or die "Couldn't connect to '$dsn' as 'myuser'" . $DBI::errstr;

      Hi Corion,

      Thanks for the help. I added (RaiseError => 1, AutoCommit => 0 ), and got the same error.

      Also, one thing that I found while going through the docs is, RaiseError is ON by default. And so the above change made no difference.

      Regards,

      ~Prithvi

        Then why do you ignore the error you get? Resolve

        DBI connect('hostname=localhost;port=1527;url=jdbc:derby:mydb%3Bsecuri +tyMechanism%3D8','myuser',...) failed: I/O Error 001bd00200010015124 +c0006114900080006000c00000005114a03 at tmp.pl line 9

        This is an error raised by the Derby DB or the Derby database driver. We cannot help you there.