Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > connect to db2 database using dbi?

Thread Tools

connect to db2 database using dbi?

Kate Perry
Posts: n/a
I am trying to execute a query on a db2 database using the dbi module. I'm wondering if someone can take a look at my code and tell me what I'm doing wrong. I'm assuming it's a problem with my query, but my query works fine in access, so I don't know. I guess I don't really understand how queries work differently in db2. I typically connect to a sql database.

Here is the error I'm getting:
Couldn't execute query: [IBM][CLI Driver][DB2] SQL0204N "(my userid here).ADXSPIT_SPI_MASTER" is an undefined name. SQLSTATE=42704
(SQL-S0002)(DBD: st_execute/SQLExecute err=-1)

My database name is DDXSPI1D, residing on server DB239. ADXSPIT.ADXSPIT_SPI_MASTER is the table name.

Here is my code:


# Include necessary modules
use CGI;
use CGI::Carp ("fatalsToBrowser");
use IO::File;
use DBI;

# create our CGI
$query = new CGI;

print "Content-Type: text/html\n\n";
print $query->start_html(-title=>"SLA DB2 TEST",);

#Include config and database info

# Get SLA that is passed into this page

# If the ProjectNum is undefined, just print out
# the form to search for a ProjectNum
if ($ProjectNum == undef)

<h1>SLA DB2 Project Test</h1>
<form name="GetProj" method="post" action="../../cgi-bin/">
Please enter a Project Number: <input type="text" size="10" name="ProjectNum">
<p><input type="submit" value="Submit">&nbsp;<input type="reset" value="Clear Form">

# Connect to the database
$dbh = DBI->connect("dbi:ODBCB239", $PROJUSER, $PROJPassword)
or die "Couldn't connect to database: $DBI::errstr\n";


#query database
$dbquery=$dbh->prepare($DB2Query) ||
die "Prepare failed: $DBI::errstr\n";

$dbquery->execute() ||
die "Couldn't execute query: $DBI::errstr\n";



#print results
print <<EOM;
<h1>SLA DB2 Project Test RESULTS</h1>
This is cool!

print $ProjInfo;

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
DB2 under Windows XP - "Missing DB2 Libraries or headers" Ruby 0 04-26-2006 03:08 PM
Installing ruby-db2-0.4 for DB2 gives SQLConnect() errors. Dinesh Ruby 0 04-03-2006 04:20 AM
Hibernate 3.1 and db2 connecting using Java 0 02-19-2006 08:20 PM
using jdbc to connect to db2 Java 1 07-27-2005 05:51 AM
How to connect to a DB2 database. Victor Reyes Ruby 4 10-28-2004 06:37 PM