Re: DBD::DB2 question need an example



What error are you seeing?

On 1/10/07, Brimacomb, Brent <brent.brimacomb@xxxxxxx> wrote:
Well I'm new to both Perl and DBD::DB2, so please bare with me.

I've installed the latest Active state Perl, the latest DBI and DBD::DB2
from CPAN.

I'm trying to develop a program that runs on a Windows server that does
a SELECT from a DB2 that's on an Os/390 box running several DB2's.
What I'm looking for is a good example of a program that does that.
Here's what I have, but I can't make the connection work......

use warnings;
use strict;
use diagnostics;

use DBI;
use DBD::DB2;
use DBD::DB2::CONSTANTS;

print "Operating System = $^O\n";
print "Perl Binary = $^X\n";
print "Perl Version = $]\n";
print "DBI Version = $DBI::VERSION\n";
print "DBD::DB2 Version = $DBD::DB2::VERSION\n\n";

my @DB2DataSources = DBI->data_sources("DB2");

print "Available DB2 DSNs:\n\n";
foreach my $dsn ( @DB2DataSources )
{
print " $dsn \n";
}

my $hostname = "dsn2.prdpl.abc123.com"; # This is the hostname of the
server you are wanting to connect to.
my $port = "5002"; # dsn port number.
my $protocol = "TCPIP"; # communication protocol
my $database = "DSN2"; # This is the database name
that you are connecting to on the above host.
my $user = "G156505"; # User that is connecting
to the database
my $password = "xxxxxx12"; # Password the User is
connecting to the database

# my $dsnx = "dbi:DB2:database=$database; HOSTNAME=$hostname;
PORT=$port; PROTOCOL=$protocol; UID=$user; PWD=$password;";
# my $dsnx = "dbi:DB2:database=USNETAALDSN2";
my $dsnx = "dbi:DB2:database=$database; HOSTNAME=$hostname; PORT=$port;
PROTOCOL=$protocol; UID=$user; PWD=$password;";


my $dbh = DBI->connect($dsnx,
$user,
$password) || die "Connection failed with error:
$DBI::errstr";

my $sql = qq( SELECT CUS_NBR, CUS_LST_NM FROM TEST.XXXR0471_CUSTAB WHERE
CUS_NBR = 535077);
print $sql;
my $sth = $dbh->prepare( $sql );
$sth->execute(); # Execute the select statement
my ( $cusno, $lastname );
$sth->bind_columns( undef, \$cusno, \$lastname );

while( $sth->fetch() ) {
print "$empno, $lastname\n";
}

$sth->finish(); # Tell the database handle you are finished with it.
$sth->disconnect(); # Disconnect from the database.


Brent Brimacomb CISSP, CISM
EDS - Information Security
MS 354
4000 North Mingo Rd.
Tulsa, OK 74116
* phone: +01-918-939-6534
* mailto:brent.brimacomb@xxxxxxx






--
--------------------------------------------------------------------------------------------------------------
The darkest places in hell are reserved for those who maintain their
neutrality in times of moral crisis.
Dante Alighieri (1265 - 1321)

They who would give up an essential liberty for temporary security,
deserve neither liberty or security.
Benjamin Franklin

Our lives begin to end the day we become silent about things that matter.
Martin Luther King

The right of the people to be secure in their persons, houses, papers,
and effects, against unreasonable searches and seizures, shall not be
violated, and no warrants shall issue, but upon probable cause,
supported by oath or affirmation, and particularly describing the
place to be searched, and the persons or things to be seized.

Amendment IV to the Constitution of the United States
--------------------------------------------------------------------------------------------------------------
.



Relevant Pages

  • Re: Evaluated "require $database" not found.
    ... DBI Error 1046: No database selected ... What I have found is that if the spaceare removed as per the correct syntax, then the DBI_errorhandler will trap and report a connection failure if a non-existent database is specified, as per this example: ... This requires that you first have an installation of mysql setup on a host ...
    (perl.dbi.users)
  • Re: Evaluated "require $database" not found.
    ... I'm familiar with error trapping as described in "perldoc DBI" - ... Transactions are a fundamental part of any robust database system. ... Ron Wingfield ... of how you do a simple DBI connection. ...
    (perl.dbi.users)
  • DBD::DB2 question need an example
    ... I've installed the latest Active state Perl, the latest DBI and DBD::DB2 ... but I can't make the connection work...... ... connecting to the database ...
    (perl.dbi.users)
  • Re: How to pass DBI handle into module
    ... > DBI connection to the same databse but with different querries. ... >>Database handle destroyed without explicit disconnect. ...
    (comp.lang.perl.misc)
  • Re: ADO Connection Timeout
    ... so what happens when a connection failure forces one station to revert ... to a local database? ... Further, you *will* have contention issues, Jet does not support record ... to the central server, but you are willing to live with periods where it ...
    (microsoft.public.data.ado)