in reply to DBD::ORacle: Not able to insert into Database
A couple things:
Those are the only problems I see. However, you might want to rearrange your code to remove the unnecessary array. You can do so like this (untested):
#!/usr/bin/perl -w use strict; use DBI; open (my $FH, '<', "test.csv") or die "Cannot open test.csv: $! \n"; my $dbh = DBI->connect ("dbi:Oracle:host=<hostname>;sid=<SID>", '<username>', ',password.', { RaiseError => 1, AutoCommit => 1, TraceLev +el => 4 } ) or die "Canot create Databse Handle: $DBI::errstr() \n"; my $sth = $dbh->prepare ("INSERT INTO CLUSTER_MAPPING (name, farm, dmz +) VALUES (?,?,?)"); <$FH>; ### this is to remove the column headers while (<$FH>) { my @row = split /,/; my $col1_value = $row[0]; my $var1 = $row[1]; $var1 =~ s/"//g; $var1 =~ s/^ //g; my $col2_value = $var1; my $col3_value = $row[2]; $sth->execute ($col1_value, $col2_value, $col3_value); } # If this is the end of your program, these lines are unnecessary, as +it'll all be # cleaned up at the end of the program. But if you're continuing to d +o something # else in your program, then by all means leave them in. $sth->finish(); $dbh->disconnect(); close $FH;
I also removed the unnecessary variable $table as I couldn't see the purpose for it.
You can do further simplifications, as well. There's no need to create new variables for the columns, you can just operate on the values in place and use them, like so:
while (<$FH>) { my @row = split /,/; $row[1] =~ s/"//g; $row[1] =~ s/^ //g; $sth->execute (@row); }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBD::ORacle: Not able to insert into Database
by slayedbylucifer (Scribe) on Jul 25, 2012 at 17:24 UTC | |
by mje (Curate) on Jul 26, 2012 at 08:25 UTC | |
by slayedbylucifer (Scribe) on Jul 28, 2012 at 05:26 UTC | |
by slayedbylucifer (Scribe) on Jul 30, 2012 at 08:40 UTC | |
|
Re^2: DBD::ORacle: Not able to insert into Database
by slayedbylucifer (Scribe) on Jul 25, 2012 at 15:18 UTC | |
by mje (Curate) on Jul 25, 2012 at 16:25 UTC | |
|
Re^2: DBD::ORacle: Not able to insert into Database
by slayedbylucifer (Scribe) on Jul 25, 2012 at 14:14 UTC |