connect to db2 database using dbi?

Discussion in 'Perl' started by Kate Perry, Jul 10, 2003.

  1. Kate Perry

    Kate Perry Guest

    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:

    #!/usr/bin/perl

    # 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
    require("../config/slaconfig.txt");

    # Get SLA that is passed into this page
    $ProjectNum=$query->param('ProjectNum');

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

    print<<EOM;
    <body>
    <center>
    <h1>SLA DB2 Project Test</h1>
    <form name="GetProj" method="post" action="../../cgi-bin/lrrform_DB2.pl">
    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">
    </p>

    </form>
    </center>
    </body>
    </html>
    EOM
    }
    else
    {
    # Connect to the database
    $dbh = DBI->connect("dbi:ODBC:DB239", $PROJUSER, $PROJPassword)
    or die "Couldn't connect to database: $DBI::errstr\n";

    $DB2Query="SELECT ADXSPIT.PROJECT_NUM, ADXSPIT.PROJECT_NAME, ADXSPIT.PROJECT_DESC FROM ADXSPIT.ADXSPIT_SPI_MASTER where
    ADXSPIT.PROJECT_NUM=$ProjectNum;";

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

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

    $ProjInfo=$dbquery->fetchrow_array;

    $dbquery->finish();

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

    </form>
    </center>
    </body>
    </html>
    EOM
    print $ProjInfo;
    }
    Kate Perry, Jul 10, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    7,588
  2. Victor Reyes

    How to connect to a DB2 database.

    Victor Reyes, Oct 28, 2004, in forum: Ruby
    Replies:
    4
    Views:
    459
    Victor Reyes
    Oct 28, 2004
  3. Dinesh
    Replies:
    0
    Views:
    154
    Dinesh
    Apr 3, 2006
  4. Replies:
    0
    Views:
    176
  5. Nicholas Quaine

    DBI:ibm_db connection for IBM DB2 database

    Nicholas Quaine, Apr 25, 2008, in forum: Ruby
    Replies:
    2
    Views:
    143
    Gerardo Santana Gómez Garrido
    Apr 29, 2008
Loading...

Share This Page