Advertisement

10.06.2007 at 08:32AM PDT, ID: 22876608
[x]
Attachment Details

creating a database table in perl

Asked by jpking72 in Perl Programming Language

Tags: perl, creating, table, database

i'm writing a program in perl to populate a database.  the code seems to be the way it should, but when i run it, the script does not create a new table.  it drops the table but doesn't create it.  i get an error message saying table does not exist when it gets to the insert statement.

#!C:\Perl\bin\perl

 #use strict;
         use DBI;
         my $dbh = DBI->connect( 'dbi:Oracle:XE',
                                 'username',
                                 'password',
                               ) || die "Database connection not made:

$DBI::errstr";

my $sql = qq {DROP TABLE CUSTOMER};
$dbh->do ($sql);

my $sql = qq { CREATE TABLE CUSTOMER (
            id INTEGER PRIMARY KEY,
            fname vARCHAR2(30),
            lname VACHAR2(30),
            street VARCHAR2(50),
            city VARCHAR2(30),
            state VARCHAR2(20),
            zip VARCHAR2(10),
            gender VARCHAR2(10)
            )};
$dbh->do ($sql);

my $insert_handle = $dbh->prepare_cached('INSERT INTO CUSTOMER (id,

fname,lname, street, city, state, zip, gender) VALUES (?,?,?,?,?,?,?,?) ');
      die "Couldn't prepare queries; aborting" unless defined

$insert_handle;

my @tuple;
my $index=1;

open(TEST, "custdata_CSV.csv");
while (<TEST>){
 
      @tuple = split(/,/,$_);
      
      print "$tuple[0]\n$tuple[1]\n$tuple[2]\n$tuple[3]\n$tuple[4]

\n$tuple[5]\n$tuple[6]\n";            

      $insert_handle->execute($index,$tuple[0],$tuple[1],$tuple[2],$tuple

[3],$tuple[4],$tuple[5],$tuple[6]);
      $index++;
 
}
close(TEST);
$dbh->disconnect();Start Free Trial
[+][-]10.06.2007 at 08:51AM PDT, ID: 20027805

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: perl, creating, table, database
Sign Up Now!
Solution Provided By: BioI
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.06.2007 at 09:08AM PDT, ID: 20027840

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628