Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

All I'm having a problem with my while loop. It reads the data out of the file and displays the first record of the array for until the end-of-file.
However, I cannot get it to insert this value into the table. Any guidence would be helpful. Thanks, Bobby

#!/usr/bin/perl # #Connects to a Sybase Database use DBI; #Loads DBI module #Connect using ARSAMSDBA.... my $dbh = DBI->connect("dbi:ODBC:usamma", "arsamsdba", "arsamssql", { PrintError => 0, RaiseError => 0 }) or die "Can't connect to database: $DBI::errstr\n"; #Prepare Create Parser Table statement.... my $sth = $dbh->prepare("CREATE TABLE PARSER_TABLE ( NIIN char(9) NOT NULL, FSC char(4) NOT NULL, PRIME_NSN varchar(16) NULL, MATCAT char(5) NULL, SOS char(3) NULL, DML char(1) NULL, EC char(1) NULL, RICC char(1) NULL, ARC char(1) NULL, SCIC char(1) NULL, AAC char(1) NULL, LCC char(1) NULL, PHC varchar(1) NULL, RC char(1) NULL, SCMC char(2) NULL, AMDF_PRICE varchar(20) NULL, CRED_SERV varchar(20) NULL, CRED_UNSERV varchar(20) NULL, UI char(2) NULL, UM char(2) NULL, MEAS_QTY varchar(20) NULL, ARI char(1) NULL, MR char(1) NULL, Nomen char(21) NULL, EIC char(3) NULL, CIIC char(1) NULL, LIN char(6) NULL, smr_cd varchar(5) NULL, WRTY char(1) NULL, WSC char(3) NULL, model varchar(50) NULL, Notes varchar(128) NULL, DEMIL char(1) NULL )" ) or die "Can't prepare SQL statement: $DBI::errstr\n"; #Excute Create Table statement.... $sth->execute or die "Can't execute SQL statment: $DBI::errstr\n"; #Disconnect ARSAMSDBA..... $dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n"; #Connect using DBA (Opens DB Handle).... $dbh = DBI->connect("dbi:ODBC:usamma", "dba", "sql", { PrintError => 0, RaiseError => 0 }) or die "Can't connect to database: $DBI::errstr\n"; #Execute to delete records from arsamsdba.parser_table.... my $sth0 = $dbh->do("DELETE arsamsdba.PARSER_TABLE") or die "Can't pre +pare SQL statement: $DBI::errstr\n"; #Prepare for input into arsamsdba.parser_table.... my $sth1 = $dbh->prepare("INSERT INTO ARSAMSDBA.PARSER_TABLE (NIIN) VA +LUES (?)"); my $sth2 = $dbh->prepare("commit"); open AFH, "D:/WorkingFiles/Scripts/perl/amdfdata.txt" or die "Can't op +en D:/WorkingFiles/Scripts/perl/amdfdata.txt: $!\n"; while(!eof AFH) { my $line = <AFH>; #take in new line chomp; #trim leading (and trailing) quotes $line =~ s/^\"//; @row=split(/\"[^\"]\"\,{0,1}/,$line); print "$row[0]\n"; $sth1->bind_param(1, $niin); $sth1->execute($row[0]); } $sth2->execute(); close AFH or warn "Can't close D:/WorkingFiles/Scripts/perl/amdfdata.t +xt: $!\n"; $dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n"; exit; #, FSC, PRIME_NSN, MATCAT, SOS, DML, EC, RICC, ARC, SCIC, AAC, LCC,PHC +, RC, SCMC, AMDF_PRICE, CRED_SERV, CRED_UNSERV, UI, UM, MEAS_QTY, AR +I, MR, #NOMEN, EIC, CIIC, #LIN, DEMIL) # VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? +,?,?,?,?)"); #$niin, $fsc, $prime_nsn, $matcat, $sos, $dml, $ec, $ricc, $arc, $scic +, $aac, $lcc, $phc, $rc, $scmc, $amdf_price, $cred_serv, #$cred_unserv, $ui, $um, $meas_qty, #$ari, $mr, $nomen, $eic, $ciic, $ +lin, $demil);

In reply to Insert into database table by curtisb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-19 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found