Query Oracle, show results (need help!!)

From: Jason Corbett (jcorbett000_at_yahoo.com)
Date: 06/08/04


Date: Tue, 8 Jun 2004 12:53:12 -0700 (PDT)
To: beginners@perl.org

Hello all. I am trying to log into an Oracle database, send this query {
select * from ban where row num < 100} and I am getting erros like:
 
can't call method 'execute' on an undefined value at (filename) line_number. Got any suggestions?
 
 
using the following perl script:
 
#!/usr/bin/perl -w
use strict;
use DBI;
# $ENV{"ORACLE_HOME"}="/orav101/oracle/8.0.6";

#Gather data for connecting to database:
 
 
print "Enter the database name that you want to connect to: ";
chomp (my $database_name1=<STDIN>);
print "Enter the username: ";
chomp (my $username=<STDIN>);
print "Enter the password: ";
chomp (my $passwd=<STDIN>);

#Must define the database here:
my $database="dbi:Oracle:$database_name1";

#Connecting to the database:database=<database_name1','$username','$passwd'

#Note the variables for username and password must be username and passwd ONLY!!
my $dbh = DBI->connect($database, $username, $passwd)
  or die "Can't connect to Oracle database: \n $DBI::errstr\n";

#Set up your sql statement that you want to run in Oracle
my $sql=qq(select * from ban where row num < 100);
 
Prepare the SQL statement for running and it'll be stored in Oracle buffer
my $sth=$dbh->prepare($sql);
 
#Execute the SQL statememt
$sth->execute || die "Couldn't execute statement";

while (my @record= $sth->fetchrow_array)
{
 for (@record){
  print ("@record");
}
print "\n\n";
}

$dbh->disconnect;
 
 
 

                
---------------------------------
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger



Relevant Pages

  • Re: Problem in authentication using asp.net for a webpage
    ... indicative of password and username not matching? ... SQL statement must be surrounded by single quotes. ... Did you think to try running your sql statement against the database outside ... >I am trying to implement a simple way to authenticate users before ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Query Oracle, show results (need help!!)
    ... After the DB connection, put this... ... I am trying to log into an Oracle database, ... Prepare the SQL statement for running and it'll be stored in Oracle buffer ...
    (perl.beginners)
  • Re: Connecting to an Oracle database
    ... the username and the password. ... The Server name is the name of the computer hosting Oracle. ... > computer where the database is. ...
    (borland.public.delphi.database.ado)
  • Re: oracle - authenticate with username and password
    ... I think we aren't clear on what the OP means by the "oracle [sic] ... The usual way to authenticate is to have a username / ... system tables), that applies to the application, not the database. ...
    (comp.lang.java.programmer)
  • Re: oracle - authenticate with username and password
    ... I get the username / password from a web form. ... But there is no such information in Oracle schema. ... the user doesn't even have a database username; the application has a username and proxies database actions based on the application authorization of the user. ... The usual way to authenticate is to have a username / password table in the application's database, that applies to the application, not the database. ...
    (comp.lang.java.programmer)